For the daily profit target it states
"TRADING TIMES/TARGET
You may optionally enter a Start/Stop time to allow trading along with a price target to end trading for the session early.(Ninjas Session must be set to Daily sessions to work right)"
I'd like to be able to have the Daily Profit Target work on a Tick/Renko chart.
Here are the sections of code pertaining to the daily target
#region Variables
#region TradeTime Variables
private int startTime1 = 0; //0930; // Time to start trading
private int stopTime1 = 0; //1600; // Time to stop trading if target not reached (1600 = 04:00PM)
private int startTime2 = 0; //0930; // Time to start trading
private int stopTime2 = 0; //1600; // Time to stop trading if target not reached (1600 = 04:00PM)
private double profitTarget = 0; // Stop trading for the day if profitTarget reached
private double priorTradesCumProfit=0; private double profitThisSession=0;
#endregion
#region Initialize
protected override void Initialize()
protected override void OnBarUpdate()
{
#region PreProcess //Only allow Trading if TradeTime/ProfitTarget/
// TRADING TIME/TARGET CHECK
//If user has selected a startTime only allow trading if Time >StartTime && Time < stopTime && Profit<profitTarget
if((tradingAllowed())&&((startTime1>0)||(startTime 2>0)) )
{ if (myPosition(0)==cLong) ExitLong(); if (myPosition(0)==cShort) ExitShort();
if ((trace)&&((startTime1>0)||(startTime1>0))) Print("Trade Time/Target Violation: "+Time[0].ToString("G")+" must be >"+(startTime1).ToString("##:##")+"and <"+(stopTime1).ToString("##:##")+" Profit is "+profitThisSession.ToString("C")+" Target is $"+profitTarget);
DrawDiamond(CurrentBar.ToString(), true,0,Low[0],Color.Yellow);
return;
}
if ((trace)&&((startTime1>0)||(startTime1>0)) ) Print("Trade Time/Target OK:"+Time[0].ToString("G")+" Session Profit:"+profitThisSession.ToString("C"));
#endregion
#region UserDefinedMethods
//
private bool tradingAllowed() // Called if user selected a trade time limit and/or profit target for the session.
{ if (Bars.FirstBarOfSession) //If first bar of session, move previous session total to cumulative total bucket
{ if(trace) Print("FirstBarOfSession");
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;
}
profitThisSession=Performance.AllTrades.TradesPerf ormance.Currency.CumProfit - priorTradesCumProfit; //store session closed trade profit/losses
if ((Position.GetProfitLoss(Close[0],PerformanceUnit.Currency)+profitThisSession)>prof itTarget) //if open trade profits plus closed session trade profits reach target add them together
{ profitThisSession=profitThisSession+Position.GetPr ofitLoss(Close[0],PerformanceUnit.Currency); //this will trigger trade violation and close trading for session
}
return ( (startTime1==0&&startTime2==0)||((ToTime(Time[0])>=startTime1*100&&ToTime(Time[0])<stopTime1*100)||(ToTime(Time[0])>=startTime2*100&&ToTime(Time[0])<stopTime2*100)&&(profitTarget==0||profitThisSess ion<=profitTarget)) );
}//ENDprofitThisSession()
Any help with this would be appreciated! Here is the full Script Automated Ninjaworkshop1.3 Strategy.zip
Comment