Code structure
Code structure
08 Aug 2017, 23:02
Hello, Can someone help me in the structure of the following code? Currently he only buys. The strategy is applied in D1 chart where: - If the day went down, he buys - If the day went high, it sells. Briefly is to do the inverse of the previous day.
thank you so much!!
private int GetSignal()
{
int Result = -1;
double Ask = Symbol.Ask;
double Bid = Symbol.Bid;
var Daily = MarketData.GetSeries(TimeFrame.Daily);
var DailyOpen = Daily.OpenTime.GetIndexByTime(MarketSeries.OpenTime[0]);
//SELL
if (DailyOpen > Ask)
Result = 0;
//BUY
else if (DailyOpen < Bid)
Result = 1;
return Result;
}
private void SendOrder()
{
switch (GetSignal())
{
case 0:
ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);
break;
case 1:
ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, SL, TP);
break;
}
}
protected override void OnBar()
{
SendOrder();
}
Replies
DelFonseca
09 Aug 2017, 20:46
RE:
dleeeq8 said:
var DailyOpen = Daily.OpenTime.GetIndexByTime(MarketSeries.OpenTime[0]);this line used index 0 for OpenTime
index 0 means first bar in history of your TimeFrame
you need to use last index or before last -> here i use last one not current open one
var DailyOpen = Daily.OpenTime.GetIndexByTime(MarketSeries.OpenTime.Last(1));for current open bar use 0:
MarketSeries.OpenTime.Last(0);if you want to see is last bar a Green or Red bar
Close - Open = +1 or -1
var dframe=MarketData.GetSeries(TimeFrame.Daily); if(dframe.Close.Last(1)-dframe.Open.Last(1) > 0) { // last Daily Bar is Green }else{ // last Daily Bar is Red }do your tests
gl
Thank you, thank you so much.
With the "dframe" code it was perfect. The other one could not apply because it gives errors that I cant solve (lack of experience). Once again, thank you !!
@DelFonseca
dleeeq8
09 Aug 2017, 08:38
this line used index 0 for OpenTime
index 0 means first bar in history of your TimeFrame
you need to use last index or before last -> here i use last one not current open one
for current open bar use 0:
if you want to see is last bar a Green or Red bar
Close - Open = +1 or -1
do your tests
gl
@dleeeq8