Confused about API
Confused about API
17 Aug 2016, 13:53
Hello everybody, I am currently creating a cBot based on a strategy which check close and the open price of different session.
Session has a starting time (06:00) and an ending time (10:00), and it uses 2 session to check which way it should trade. I got the session working and everything my only problem is that both session get the same open and close value even though I specify that it should get the values from the candle that closed on 10am. I was wondering if any of you could point to the error in my code or if you could give advice. Hope it makes sense.
Code for getting Open and Close price:
void fillData(ref TradingSession session) { session.IsFilled = false; session.Open = double.NaN; session.High = double.NaN; session.Low = double.NaN; session.Close = double.NaN; for (int i = MarketSeries.Close.Count - 1; i >= 0; i--) { if (!session.IsFilled) { session.Open = MarketSeries.Open[i]; session.High = MarketSeries.High[i]; session.Low = MarketSeries.Low[i]; session.Close = MarketSeries.Close[i]; session.IsFilled = true; continue; } session.Open = MarketSeries.Open[i]; session.High = Math.Max(session.High, MarketSeries.High[i]); session.Low = Math.Min(session.Low, MarketSeries.Low[i]); } //Print("Out of for"); }
Code for placing order:
void calculateWay() { double entryPrice = 0.0; double? TP_pips = null, SL_pips = null; long volume = 0; // // if (m_Session1.Open < m_Session1.Close && m_Session2.Open < m_Session2.Close) { //buy evaluateEntryRules(); ExecuteMarketOrder(TradeType.Buy, Symbol, LotSize); Print("Buy! with {0} + {1} and {2} + {3}", m_Session1.Open, m_Session1.Close, m_Session2.Open, m_Session2.Close); } else { Print("No buy with {0} + {1} and {2} + {3}", m_Session1.Open, m_Session1.Close, m_Session2.Open, m_Session2.Close); } if (m_Session1.Open < m_Session1.Close && m_Session2.Open < m_Session2.Close) { //sell evaluateEntryRules(); ExecuteMarketOrder(TradeType.Sell, Symbol, LotSize); Print("Sell! with {0} + {1} and {2} + {3}", m_Session1.Open, m_Session1.Close, m_Session2.Open, m_Session2.Close); } else { Print("No sell with {0} + {1} and {2} + {3}", m_Session1.Open, m_Session1.Close, m_Session2.Open, m_Session2.Close); } }
Replies
Szabolcs.sajben
18 Aug 2016, 16:10
( Updated at: 21 Dec 2023, 09:20 )
Hi @lucian!
Thanks that allowed made to make adjustments and worked, NOW my problem is that in backtest it shows this and I am confused as to why there are no trades (I am using ExecuteMarketOrder) but I lose money:
@Szabolcs.sajben
... Deleted by UFO ...