HasCrossedAbove///HasCrossed Below
HasCrossedAbove///HasCrossed Below
13 Sep 2016, 18:46
Hi,
I want to create a signal if the current close (daily bar) crosses the movingaverage. I am using the code below but get an error.
double close = daily.Close.LastValue;
bool isCrossDown = Functions.HasCrossedAbove(close, ma.Result, 0);
bool isCrossUp = Functions.HasCrossedBelow(close, ma.Result, 0);
"The best overloaded method match for calgo.api.function.hascrossedabove... has some invalid arguments. Argument 1 cannot convert from double to cAlgo.Api.Dateseries.
Now when I change the 2 bools to
bool isCrossDown = Functions.HasCrossedAbove(ma.Result,close, 0);
bool isCrossUp = Functions.HasCrossedBelow(ma.Result, close, 0);
I don't get an error however this would imply that the moving average crosses above the close!?
Any help would be much appreciated.
Thanks
Replies
DELETED_USER
13 Sep 2016, 23:33
RE: RE:
I am interested in the actual daily bar's close.
Symbol.Bid > ma.Result.LastValue would be called everytime the bid is above the MA. I am interested when the DailyBar closes above (crosses above) the MA for the first time.
Wouldn't daily.Close.Last(1) > ma.Result.LastValue be called everytime the last close is above the MA?
croucrou said:
Unless you are interested in the previous bar's close, then:
if (daily.Close.Last(1) > ma.Result.LastValue) //buy if (daily.Close.Last(1) < ma.Result.LastValue) //sellAssuming, that the "ma" is also based on the daily timeframe series.
croucrou
14 Sep 2016, 01:08
Crossing above happens in a real time and closing happens on the end of the previous bar.
I assume it is the first case, so I would use Symbol Bid/Ask to discard the spread instead of daily.Close.LastValue.
You are right, to make it complete, you would need to add:
if (Symbol.Bid > ma.Result.LastValue && daily.Open.Last(0) < ma.Result.LastValue) //buy if (Symbol.Ask < ma.Result.LastValue && daily.Open.Last(0) > ma.Result.LastValue) //sell
@croucrou
7010372
21 Feb 2021, 08:19
How to make Robot close after one Buy trade?
Hi
Does anyone know how to make Robot STOP after one trade when profit target is achieved? Normally when you put a Profit target Robot closes the position and then immidietely opens another position as the criteria tells it to open a position (when market price or Bar is above MA).,Please help.
thanks
Ear Zakaria
@7010372
PanagiotisCharalampous
22 Feb 2021, 08:18
Hi Ear,
You can use Stop() method to stop a cBot.
Best Regards,
Panagiotis
@PanagiotisCharalampous
croucrou
13 Sep 2016, 20:17
Can't you just write it like:
@croucrou