[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: plot all my trades



PureBytes Links

Trading Reference Links

thanks all for jumping in with ideas. here is what i am trying to 
achieve. i am trying to plot my real trades on AB so i can use to 
review it. i have a working copy if i chart only 1 entry and 1 exit. 
i want to enhance it to accomodate multiple entries and exits because 
i use scaling in the real trading world.

for the entries and exits, i just store the data in the as static 
variables.

so in the next upgrade i want to make, i will create the static 
varibles containing entries and exits in the comma delimited way and 
also indicate the no of entries and exits there are. 
the challenges are 
1. how to compare the comma delimited entrie and exits against the 
price array.

below is working code for single entry/exit which is just the first 
step.





function returnBarIndex(array)
{
	indx=-1;
	for (i=1; i<BarCount;i++)
		{

			if(array[i] ==True )
				{
					indx=i;
				}
		}
	return indx;
}



function returnShiftedArray(array,shift)
{

	
	newArray=array;
	 for (i=1; i<BarCount;i++)
		{

			if((array[i] ==True ) && ((shift+i)>=0) && 
((shift+i)<BarCount))
				{
					
					newArray[shift+i]=True;
					newArray[i]=False;

					
				}
		}


	return newArray;
}
TradeType= StaticVarGetText( "TradeType" );
forexSymbol= StaticVarGetText( "forexSymbol" );
StockSymbol= StaticVarGetText( "StockSymbol" );
ShortOrLong= StaticVarGetText( "ShortOrLong" );
EntryPrice= StaticVarGet( "EntryPrice" );
ExitPrice= StaticVarGet( "ExitPrice" );
EntryDate= StaticVarGet( "EntryDate" );
ExitDate= StaticVarGet( "ExitDate" );
EntryTime= StaticVarGet( "EntryTime" );
ExitTime= StaticVarGet( "ExitTime" );
switch (Interval())
{
	case in1Minute:
	case in5Minute:
	case in15Minute:
	case inHourly:
	
 
			//entry=Name()==STOCKNAME AND BarIndex()
==ValueWhen((DateNum()==EntryDate  ) AND (TimeNum()>=EntryTime AND Ref
(TimeNum(),-1)<EntryTime), BarIndex());	
			entry=returnShiftedArray(Name()==STOCKNAME 
AND BarIndex()==ValueWhen((DateNum()==EntryDate  ) AND (TimeNum()
>=EntryTime AND Ref(TimeNum(),-1)<EntryTime), BarIndex()),-1);	
			exit=returnShiftedArray(Name()==STOCKNAME  
AND BarIndex()==ValueWhen((DateNum()==ExitDate)   AND  (TimeNum()
>=ExitTime AND Ref(TimeNum(),-1)<ExitTime) , BarIndex() ),-1);	
				// need to shift the bars by -1 as 
the time match returns teh bar after the trade is made. so shifting 
it by -1;


	//_TRACE("ABTest:  aa " + returnBarIndex(aa));	

_TRACE("ABTest:  entry " + returnBarIndex(entry));


			//entryin5Minute=TimeFrameCompress( 
entryin1Minute, in5Minute ); 
			//_TRACE("ABTest: 5 minute bar " + 
returnBarIndex(TimeFrameExpand( entryin5Minute, in5Minute )));
			//EntryBarIndexin5Minute=returnBarIndex
(entryin1Minute);
			//_TRACE("ABTest: " + EntryBarIndexin5Minute);

			_TRACE("ABTest: "+ GetChartID()  +  "VALUE 
STOCKNAME " + STOCKNAME );
			_TRACE("ABTest: "+ GetChartID()  +  " Name
() " + Name() );


			_TRACE("ABTest: "+ GetChartID()  + " 
EntryBarIndex " + WriteVal(entry));
			_TRACE("ABTest: "+ GetChartID()  + " 
eXITBarIndex " + WriteVal(exit));

			break;
 				// there is no time if i use daily as 
the time shown is the start of trade on trading day.
	case inDaily:
			entry=Name()==STOCKNAME AND BarIndex()
==ValueWhen(DateNum()==EntryDate   , BarIndex());	
			exit=Name()==STOCKNAME  AND BarIndex()
==ValueWhen(DateNum()==ExitDate    , BarIndex());
			break;
			
	case inWeekly:
// there is no time if i use daily as the time shown is the start of 
trade on trading day. the trade candle spans 5 days.

			entry=Name()==STOCKNAME AND BarIndex()
==ValueWhen((DateNum()>=EntryDate AND Ref(DateNum(),-1)<EntryDate  ), 
BarIndex());	
			exit=Name()==STOCKNAME  AND BarIndex()
==ValueWhen((DateNum()>=ExitDate AND Ref(DateNum(),-1)
<ExitDate )    , BarIndex());
			break;

	
	
}

switch(ShortOrLong){
		case "Long":
			Buy=entry;
			Sell=exit;
			Short=False;
			Cover=False;	
			_TRACE("ABTest: "+ GetChartID()  +  "VALUE 
STOCKNAME " + STOCKNAME );
			_TRACE("ABTest: "+ GetChartID()  +  " Name
() " + Name() );			
			_TRACE("ABTest: "+ GetChartID()  +  " 
ShortOrLong " +ShortOrLong );	
		break;
		
		
		case "Short":
			Buy=False;
			Sell=False;
			Short=entry;
			Cover=exit;
		_TRACE("ABTest: "+ GetChartID()  +  "VALUE 
STOCKNAME " + STOCKNAME );
			_TRACE("ABTest: "+ GetChartID()  +  " Name
() " + Name() );			
			_TRACE("ABTest: "+ GetChartID()  +  " 
ShortOrLong " +ShortOrLong );
	break;

		
}


PlotShapes( IIf(Buy OR Short, shapeSmallCircle, 
shapeNone),colorBrightGreen, 0, EntryPrice, 0 );
PlotShapes( IIf( Sell OR Cover, shapeSmallCircle, 
shapeNone),colorRed, 0 ,ExitPrice, 0 );





--- In amibroker@xxxxxxxxxxxxxxx, "Barry Scarborough" <razzbarry@xxx> 
wrote:
>
> When you set up a "private" array you cannot directly compare that 
> array with any array set by AFL. If you look at DateNumOfBuy[0] 
which 
> has only a few members with Buy array which may have hundreds then 
you 
> ill be comparing similar it to buy[0[], not what you wnat. Unless 
you 
> use a loop and compare the date in your array to the one in the bar 
> they will never be in sync. Using a loop in this way will make auto 
> analysis much more difficult or totally incorrect. 
> 
> Buy why don't you just use buyprice, also sellprice, coverprice and 
> shortprice, to keep your trade prices and then plotshapes to show 
them 
> on your chart? This will keep all the arrays in sync. 
> 
> Set buyprice to the value of C when the condition is true. For 
example, 
> if you use MA crossing then put the value of one of the MAs in 
> BuyPrice. If you use C it will end up being the close of the bar, 
not 
> necessarily the price when the condition was true. Even the MA 
price 
> may not be exact but it will be much sloser to the real trading 
value. 
> 
> buyprice = iif(buy condition, value when the condition is true, 0);
> 
> then chart the buy point with either
> PlotShapes(Buy 	* shapeUpArrow, colorgreen); 
> PlotShapes(iif(Buyprice, shapeUpArrow, 0), colorgreen); 
> 
> Plot the buyprice so you can click on the bar and see its value,
> plot(buyprice, "\nBuyPrice", colorblack, stylenoline | 
styleownscale);
> 
> Setting buyprice will also let you use it in automatic analysis.
> 
> Barry
> 
>  --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> >
> > i am trying to chart my trades including the buy and sell points. 
so 
> my 
> > feed into afl is going to be like following as it may be multiple 
> > trades.
> > DateNumOfBuy[0] = 1080722;
> > DateNumOfBuy[1] = 1080723;
> > 
> > Buy=IIf(DateNum()==DateNumOfBuy,True,False);
> > 
> > when i actually scan it, the buy signal never gets a true. i am 
> > obviously missing something. appreciate your response.
> >
>



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/