Please find the code below:
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
///
/// </summary>
[Description("")]
public class S01test : Strategy
{
#region Variables
// Dane instrumentu
private string inst = "";
private int ctf = 0;
// Parametry
private W01v01 w;
private int o_entry = 20;
private int o_sl = 20;
private int kierunek = 1;
private int ryzyko = 50000;
private double kurs = 1;
// Zlecenia
private IOrder O_Long_0 = null;
private IOrder O_Long_1 = null;
// Backtest
private bool bt = false;
#endregion
/// <summary>
/// </summary>
protected override void Initialize()
{
if (bt)
{
Add("$EURJPY", BarsPeriod.Id, BarsPeriod.Value);
}
CalculateOnBarClose = true;
TraceOrders = true;
}
/// <summary>
/// </summary>
protected override void OnBarUpdate()
{
if (bt && BarsInProgress == 0)
{
return;
}
if (CurrentBar < BarsRequired)
{
return;
}
inst = Instrument.MasterInstrument.Name;
ctf = BarsPeriod.Value;
w = W01v01(kierunek, o_entry, o_sl);
// M03 Start | W piatek po 21:00 nic nie robimy (tylko dane Live)
if (!Historical && Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) > 210000)
{
Print(Time[0]+ " | " + DayOfWeek.Friday);
return;
}
// M03 End | W piatek po 21:00 nic nie robimy
// LONG
if (kierunek == 1 && w.DC.ContainsValue(0) && w.DC[0] == 0)
{
if (BarsInProgress == 0) {M01L(BarsInProgress, ref O_Long_0);}
if (BarsInProgress == 1) {M01L(BarsInProgress, ref O_Long_1);}
}
if (kierunek == 1 && Position.MarketPosition == MarketPosition.Long &&
DonchianChannel(o_sl).Lower[0] > DonchianChannel(o_sl).Lower[1])
{
M02L(BarsInProgress);
}
}
#region M01 LONG | USTAWIENIE ZLECENIA DONCHIAN
void M01L(int bip, ref IOrder O_L)
{
double entry = DonchianChannel(o_entry).Upper[0] + 3 * TickSize;
double sl = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
int psize = (int) ((ryzyko / (entry - sl)) * kurs);
//Wymogi FXCM -> wielkosc pozycji = min. 1000 i dalej wielokrotnosc 1000
if (psize >= 800)
{
int psize_fxcm = (int)(Math.Round((double)psize/1000, 0) * 1000);
O_L = EnterLongStop(bip, true, psize_fxcm, entry, "Long_"+bip);
SetStopLoss("Long_"+bip, CalculationMode.Price, sl, false);
Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Zlecenie LONG | PSize = " +psize+ "/" +psize_fxcm);
}
if (psize < 800)
{
Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Brak zlecenia LONG - za male PSize (" +psize+ ")");
}
}
#endregion
#region M02 LONG | PROWADZENIE POZYCJI DONCHIAN
void M02L(int bip)
{
double ts = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
SetStopLoss("Long_"+bip, CalculationMode.Price, ts, false);
}
#endregion
}
}
A1. I run the above code on $EURJPY with bt = false
A2. I get trade parameters as given in the attachment 1
B1. I run the above code on $EURJPY with bt = true
B2. I get trade parameters as given in the attachment 2
Please note I get different entry price.
In B case, my entry price do not get updated. The reson is: 'Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'.
I use Entry handling = UniqueEntries and Entriesperdirection = 1.
Why is this happening? My understandig is that it should be the same in both situations.
Can you help me what am I doing wrong here?
Just in case I have also sent you mail to support with trace and logs files along with link to this thread.

Comment