Now, I'm attempting to place a profit target at the same price as the Reward line of the RiskReward drawing and I cannot figure it out (I am very new so I'm sure this is simple or simply not possible).
The code I have now, which I'll paste below, does hit profit targets but I can't see any correlation with the levels set by the RiskReward tool.
Any guidance or assistance would be greatly appreciated.
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies.EmaTest.Long
{
public class BesrForBullWPT : Strategy
{
private int TradeCounter;
private EMA EMA1;
private VWAP VWAP1;
private EMA EMA2;
private ExampleMADifference ExampleMADifference1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enters long position when price crosses below EMA[50] and closes above it. ";
Name = "BestForBullWPT";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
ProfitTarget = 1000;
StopLoss = 1000;
EmaDifference = 0;
MaxTrades = 100;
EntryEmaOffset = 0;
EmaDiffMinAgo = 1;
RiskReward = 1;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 50);
VWAP1 = VWAP(Close);
EMA2 = EMA(Close, 50);
ExampleMADifference1 = ExampleMADifference(Close);
EMA1.Plots[0].Brush = Brushes.SteelBlue;
ExampleMADifference1.Plots[0].Brush = Brushes.Goldenrod;
SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
}
}
protected override void OnBarUpdate()
{
if (Bars.IsFirstBarOfSession)
{
TradeCounter = 0; // reset on new trading day
}
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 10)
return;
// Set 1
if ((EMA1[0] > VWAP1.PlotVWAP[0])
&& (Position.MarketPosition == MarketPosition.Flat && TradeCounter < MaxTrades)
&& (Low[1] <= EMA2[1] + (EntryEmaOffset * TickSize))
&& (Close[1] >= EMA2[1])
&& (Close[0] > EMA2[0])
&& (Close[1] > EMA2[1] + (4 * TickSize))
// between times
&& (Times[0][0].TimeOfDay > new TimeSpan(8, 30, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(16, 0, 0))
// AddOns
&& ((ExampleMADifference1[0] > EmaDifference)
&& (ExampleMADifference1[0] > ExampleMADifference1[EmaDiffMinAgo])))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "Long");
TradeCounter++;
//drawing
Draw.RiskReward(this, "tag1" + CurrentBar, true, 0, Close[0], -15, (Low[1] - (4 * TickSize)), RiskReward, true);
//problem area
SetProfitTarget(CalculationMode.Ticks, (Convert.ToInt32(Close[0] - (Low[1] - (4 * TickSize)))));
}
// Set 2
if ((Close[0] < EMA2[0])
&& (Low[1] < EMA2[1])
|| (Times[0][0].TimeOfDay > new TimeSpan(16, 38, 0)))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
Print (Time[0]+"TradeCount = "+TradeCounter);
}
region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ProfitTarget", Order=2, GroupName="Parameters")]
public int ProfitTarget
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="StopLoss", Order=3, GroupName="Parameters")]
public int StopLoss
{ get; set; }
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="EmaDifference", Order=4, GroupName="Parameters")]
public int EmaDifference
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="MaxTrades", Order=1, GroupName="Parameters")]
public int MaxTrades
{ get; set; }
[NinjaScriptProperty]
[Range(-16, int.MaxValue)]
[Display(Name="EntryEmaOffset", Order=5, GroupName="Parameters")]
public int EntryEmaOffset
{ get; set; }
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="EmaDiffMinAgo", Order=6, GroupName="Parameters")]
public int EmaDiffMinAgo
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="RiskReward", Order=7, GroupName="Parameters")]
public double RiskReward
{ get; set; }
#endregion
}
}

Comment