I am learning to write my strategy ideas but need some guidance. I have a set of conditions that all must be met for a trade to be placed but I am not getting the desired result. Please can you explain the correct way to code the conditions.
In my strategy I have the following conditions to be met before the order is placed: Here are the conditions in order
1) strxav2 == "UT" && strxav1 == "UT" // Called from indicator
2) strsignal == "MACD Cross UP" // Called from an indicator
3) ADX(14)[0] > ADXlong // Set at 20 //
4) Close[0] > SMA(36)[0] // Price is above the SMA
So I require all 4 to match to enter an order I have this as follows:
if (strxav2 == "UT" && strxav1 == "UT" && strsignal == "MACD Cross UP" && ADX(14)[0] > ADXlong && Close[0] > SMA(36)[0])
//if (Position.MarketPosition == MarketPosition.Flat)
{
Print("-----------RGAuto:" + strsignal);
Print("signal:" + strsignal + " XAV1:" + strxav1 + " Xav2:" + strxav2);
{
int n = 0;
EnterLong(lots, "UT+UT");
//EnterLongStopLimit(0, true, 1, High[0] + 4 * TickSize, High[0] + 4 * TickSize, "UT+UT");
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Ninja Trader7\MyScalper");
key.SetValue("signalname", "UT+UT.Long");
key.Close();
}
}
Now when I run the strategy, the results are sporadic. it seems to adhere to separate conditions on separate occasions rather than meeting all to enter the trade.
Can you please explain how to code this to meet all conditions before trade entry.
Thank you
Comment