I am still learning.
I am stuck, try and error.
The code is attached. It opens trades when the bar closes 200EMA, 50EMA, and PSAR
Issue: 1. it keeps opening trades as long as the price is above 200EMA. 50EMA and PSAR.
Please can you help with what code to add to allow the bot to open ONLY 1 trade not the continuation of trades?
- Parameters "bool" YES or NO do not work does not matter if selected or not. What code is required to make this option work.
protected override void OnStart()
{
//Load indicators on start up
pSAR = Indicators.ParabolicSAR(MinAF, MaxAF);
maFast = Indicators.MovingAverage(Source, MaFastPeriod, MaFastType);
maSlow = Indicators.MovingAverage(Source, MaSlowPeriod, MaSlowType);
volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
Print("Current EMA Value:", maSlow.Result.Last(0));
Print("Current EMA Value:", maSlow.Result.Last(0));
}
protected override void OnBar()
{
int total = Bars.ClosePrices.Count;
// Put your entry logic here
{
if (Bars.ClosePrices.Last(0) > pSAR.Result.Last(0) && Bars.ClosePrices.Last(0) > maFast.Result.Last(0) && Bars.ClosePrices.Last(0) > maSlow.Result.Last(0) && Positions.Count==0)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "Price Cross", SL, TP);
}
else if (Bars.ClosePrices.Last(0) < pSAR.Result.Last(0) && Bars.ClosePrices.Last(0) < maFast.Result.Last(0) && Bars.ClosePrices.Last(0) < maSlow.Result.Last(0) && Positions.Count==0)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, volumeInUnits, "Price Cross", SL, TP);
}