[amibroker] Re: Is there any way to get the last signal (buy or sell) and the last order price? [1 Attachment]

 
[Attachment(s) from kastinhelia@yahoo.com.au [amibroker] included below]

Ok try this code, 


you should be able to see what i did, 
in the "lastsell = ValueWhen(Cross(the100,the5),C,1);"  the C array at the end i just assumed you are using close bar prices for buy and sell price, change these to what ever. 

debug and trace are above my skill level at the moment hahah
But you'll see at the bottom of the code i use those to print assignments and arrays to the top of the screen and i find it helps with my debugging.






_SECTION_BEGIN("for testing");


SetTradeDelays( 0, 0, 0, 0 ); /* delay entry/exit by one bar */
//SetTradeDelays(buydelay, selldelay, shortdelay, coverdelay);
SetOption( "initialequity", 1000000 ); /* starting capital */
SetPositionSize( 1000, spsShares );
//PositionSize = -10;/* trade size will be 20% of available equty */
SetOption("AllowSameBarExit",false); 
SetOption( "MaxOpenPositions", 10 ); /* I don't want to comit more than 60% of Equity at any one time */
SetOption( "PriceBoundChecking", True ); /* trade only within the chart bar's price range */
//SetBacktestMode( backtestRegularRawMulti );
SetBacktestMode( backtestRegular );
//SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption("ActivateStopsImmediately",True);


the100a = Optimize("the100",100,20,100,20);
the100 = MA(C,the100a);
the5a = Optimize("the5",5,2,10,1);// 10
the5 = MA(C,the5a);
//Plot( MA( Close, the5a ), "Fast Avg", ParamColor( "Color-Fast", colororange ), styleDashed ); 
//Plot( MA( Close, the100a ), "Fast Avg", ParamColor( "Color-Fast", colororange ), stylethick ); 

diff = 1.001;




//lastbuyprice = ValueWhen(Buy,BuyPrice,1);
//lastsellprice = ValueWhen(sell,sellPrice,1);

buycond1 = Cross(the5,the100);
lastsell = ValueWhen(Cross(the100,the5),C,1);
buycond2 = C < (lastsell*diff);

Buy = buycond1 OR buycond2;

sellcond1 = Cross(the100,the5);
lastbuy = ValueWhen(Cross(the5,the100),C,1);
sellcond2 = C > (lastbuy*(1-diff));


Sell = sellcond1 OR sellcond2;


Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

PlotShapes(IIf(buy,shapeupArrow, shapeNone), colorgreen, 0, L, -60);
PlotShapes(IIf(sell,shapesmallcircle,shapeNone), colorred, 0, L, 60);


Title = EncodeColor(colorWhite)+"  "+  Date()+"   "+EncodeColor(colorWhite)+shortprice+ "\n"+ 
EncodeColor( colorWhite)  + "   BuyPrice  "+EncodeColor(47)+ buyPrice + "\n"+
EncodeColor( colorWhite)  + "   sellprice  "+EncodeColor(47)+ SellPrice + "\n"+
EncodeColor( colorWhite)  + "   lastbuyprice  "+EncodeColor(47)+ lastbuy + "\n"+
EncodeColor( colorWhite)  + " lastsellprice     =  " + EncodeColor(47)+ lastsell + "\n"+
EncodeColor( colorWhite)  + "open " + EncodeColor(47)+ Open + "\n"+
EncodeColor( colorWhite)  + "high " + EncodeColor(47)+ High + "\n"+
EncodeColor( colorWhite)  + "low " + EncodeColor(47)+ Low + "\n"+
EncodeColor( colorWhite)  + "close  " + EncodeColor(47)+ Close + "\n"+
GraphXSpace=5;


_SECTION_END();

__._,_.___

Attachment(s) from kastinhelia@yahoo.com.au [amibroker] | View attachments on the web

1 of 1 File(s)


Posted by: kastinhelia@yahoo.com.au
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (8)
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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


.

__,_._,___

Related Posts


EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng
:lv