Hi,
The below code calculates a signal based o the closing values of multiple securities. If the signal is >0 go long at a limit price and if <0 go short at limit price on the next bar.
First, am I correctly implementing the limit price? If the limit price is not met, no trade will occur, correct?
Second,assuming have the limit logic correct, the code will enter on the bar after the signal is generated with SetTradeDelays( 1,1,1,1). I am a bit confused here because I am using "Buy = Ref( Val, -1) > 0.0;" in the limit logic.
Third, once a trade is entered at a limit price, what are the correct settings for ApplyStops?
Thank you for your help.
Mike
_SECTION_BEGIN("");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetOption("MaxOpenPositions", 14);
//SetTradeDelays( 0, 0, 0, 0 );
SetTradeDelays( 1,1,1,1);
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
Leverage=3.00;
SetOption("AccountMargin",1);
SetPositionSize (((100/14)*Leverage),spsPercentofEquity);
SetOption( "AllowPositionShrinking", True );
FirstTradeTime= 060000;
SquareOffTime = 150000;
DaySessionEndTime =160000;
NO_TRADE = 170000;
LookBack =1;
function mROC( symbol, mode )
{
fO = Foreign( symbol, "O");
fC = Foreign( symbol, "C");
fH = Foreign( symbol, "H");
fL = Foreign( symbol, "L");
switch ( mode )
{
case "CC1":
returnvalue = ROC( fC, LookBack );
break;
case "OC0":
returnvalue = (fC- fO)/fO*100;
break;
default:
returnvalue = Null;
break;
}
return returnvalue;
}
n = Name();
AUDCAD_IDEALPRO_CASH_30Val =mROC("NZDUSD.FXCM","CC1")*-1.48+mROC("EURUSD.FXCM","CC1")*-0.42+mROC("USDJPY.FXCM","CC1")*1.5+mROC("USDCHF.FXCM","CC1")*1.5+mROC("GBPNZD.FXCM","CC1")*0.30;
AUDCHF_IDEALPRO_CASH_30Val =mROC("EURUSD.FXCM","CC1")*-1.5+mROC("USDCAD.FXCM","CC1")*1.5+mROC("EURNZD.FXCM","CC1")*-0.32+mROC("EURAUD.FXCM","CC1")*-1.48+mROC("EURGBP.FXCM","CC1")*0.27;
Val=IIF(n=="AUDCAD.FXCM", AUDCAD_IDEALPRO_CASH_30Val,
IIF(n=="AUDCHF.FXCM", AUDCHF_IDEALPRO_CASH_30Val ,
AUDchf_IDEALPRO_CASH_30Val));
//Long & Short Entrt LIMIT logic
// enter on the next bar if the close Val >0 or short <0 of previous and at limitPrice logic is met
Buy = Ref( Val, -1) > 0.0;
Short = Ref( Val, -1) < 0.0;
LimitMultiplier=10.0;
BuyLimitPrice = Open-(0.0001*LimitMultiplier);
ShortLimitPrice = Open+(0.0001*LimitMultiplier);
Buy = Buy AND L < BuyLimitPrice;
Short = Short AND H > ShortLimitPrice;
//entry/exit pricing
BuyPrice = Min( Open, BuyLimitPrice );
ShortPrice = Max( Open, ShortLimitPrice );
SellPrice=Open;
CoverPrice=Open;
//balance of entry/exit logic
Buy= Buy AND TimeNum()>= FirstTradeTime AND TimeNum()<SquareOffTime ;
Sell = Val < 0.0 OR TimeNum()>=DaySessionEndTime;//US hours
Short= Short AND TimeNum()>= FirstTradeTime AND TimeNum()<SquareOffTime ;
Cover=Val > 0.0 OR TimeNum()>=DaySessionEndTime; //US hours
//stops - what are settings if entering on next bar at a limit price?
StopLoss=optimize("SL",0.125, 0.125,0.25,0.0625);//2 0.125;
Target=optimize("Target",0.25,0.25,0.50,0.25);//0.2 0.75;
StopDelay=optimize("StopDelay",10, 0,10,2);//2 0.125; 16
TargetDelay=optimize("TargetDelay",2,0,10,2);//0.2 0.75; 4
SetOption("ActivateStopsImmediately", True) ;
IIf(TimeNum()== No_Trade,(ApplyStop(Type=0,Mode=1,Amount=50, 1,False,ReentryDelay=4,ValidFrom=0)),(ApplyStop(Type=0,Mode=1,Amount=StopLoss, 1,False,ReentryDelay=StopDelay,ValidFrom=0)));
ApplyStop(Type=1,Mode=1,Amount=Target ,1,False,ReentryDelay=TargetDelay,ValidFrom=0) ;//, ExitAtStop=1);
Filter= Buy OR Sell OR Short OR Cover;
filter = close > 0;
AddColumn( Close, "Close" );
AddColumn( Val, "Rule Val" );
AddColumn( IIf( Buy, 'B', 'S' ), "Signal", formatChar );
AddColumn( IIf( Short, 't', 'c' ), "Signal", formatChar );