Hi,
I have some problems with getting data2 to work properly and I would really appreciate if I could get some guidance in how to resolve it.
I have attached a couple of picture of the code.
There is no error message when compiling the code but the data I'm trying to get from data2 is not correct unfortunately, ie the values from the moving averages is not correct.
Problem with data2 [SOLVED]
-
- Posts: 5
- Joined: 12 Jun 2023
Problem with data2
- Attachments
-
- Skärmbild 2023-05-07 183949.png
- (3.84 KiB) Not downloaded yet
-
- Skärmbild 2023-05-07 161925.png
- (4.93 KiB) Not downloaded yet
-
- Skärmbild 2023-05-07 161811.png
- (8.62 KiB) Not downloaded yet
Re: Problem with data2
Hi,
You might try this:
You might try this:
Code: Select all
Vars: SMA10H (0, Data2) ;
SMA10H = AverageFC ( Close, 10) Data2 ;
-
- Posts: 5
- Joined: 12 Jun 2023
Re: Problem with data2
Hi,
Thank you for your reply. I've tried it now but with the same result as before I'm afraid.
To illustrate an example here's a code that buy if SMA10 on hourly is above or equal to SMA20 and sell if below.
To check the value of SMA10-SMA20 when buiyng or selling I print it to the output. If buy condition is met it should print SMA20-SMA10 which then would be a negative value. If sell condition is met it should print SMA10-SMA20 which would also be a negative value. Hence it should only be negative values in the output window. But there is only positive values. Maybe there is something else that I have misunderstood?
Here is the code:
And the output window is attached in an image file.
Thank you for your reply. I've tried it now but with the same result as before I'm afraid.
To illustrate an example here's a code that buy if SMA10 on hourly is above or equal to SMA20 and sell if below.
To check the value of SMA10-SMA20 when buiyng or selling I print it to the output. If buy condition is met it should print SMA20-SMA10 which then would be a negative value. If sell condition is met it should print SMA10-SMA20 which would also be a negative value. Hence it should only be negative values in the output window. But there is only positive values. Maybe there is something else that I have misunderstood?
Here is the code:
Code: Select all
Vars:
SMA10H (0, data2),
SMA20H (0, data2),
HOURLYUPTREND (False),
HOURLYDOWNTREND (False);
//Check hourly moving averages
SMA10H = Average(Close,10) data2;
SMA20H = Average(Close,20) data2;
//Check trend on hourly timeframe
If SMA10H - SMA20H >= 0 then
begin
HOURLYUPTREND = True;
HOURLYDOWNTREND = False;
end;
If SMA10H - SMA20H < 0 then
begin
HOURLYDOWNTREND = True;
HOURLYUPTREND = False;
end;
//Buy condition
If HOURLYUPTREND then
Buy 1 contract next bar market;
Print((SMA20H - SMA10H));
If HOURLYDOWNTREND then
SellShort 1 contract next bar market;
Print((SMA10H - SMA20H));
- Attachments
-
- Skärmbild 2023-06-13 121050.png
- (2.3 KiB) Not downloaded yet
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
Re: Problem with data2
ATCOTrader,
"if ... then..." statetements will only span until the end of the statement (next semicolon). Therefore, you are printing unconditionally and this might explain the results you are getting. Including your buy and sell statements with the prints in a "if...then begin" conditional branch should only print when the order conditions are met. To make your checking easier, it can make sense to include the time and date of the bar in your prints.
Regards,
ABC
"if ... then..." statetements will only span until the end of the statement (next semicolon). Therefore, you are printing unconditionally and this might explain the results you are getting. Including your buy and sell statements with the prints in a "if...then begin" conditional branch should only print when the order conditions are met. To make your checking easier, it can make sense to include the time and date of the bar in your prints.
Regards,
ABC
Hi,
Thank you for your reply. I've tried it now but with the same result as before I'm afraid.
To illustrate an example here's a code that buy if SMA10 on hourly is above or equal to SMA20 and sell if below.
To check the value of SMA10-SMA20 when buiyng or selling I print it to the output. If buy condition is met it should print SMA20-SMA10 which then would be a negative value. If sell condition is met it should print SMA10-SMA20 which would also be a negative value. Hence it should only be negative values in the output window. But there is only positive values. Maybe there is something else that I have misunderstood?
Here is the code:And the output window is attached in an image file.Code: Select all
Vars: SMA10H (0, data2), SMA20H (0, data2), HOURLYUPTREND (False), HOURLYDOWNTREND (False); //Check hourly moving averages SMA10H = Average(Close,10) data2; SMA20H = Average(Close,20) data2; //Check trend on hourly timeframe If SMA10H - SMA20H >= 0 then begin HOURLYUPTREND = True; HOURLYDOWNTREND = False; end; If SMA10H - SMA20H < 0 then begin HOURLYDOWNTREND = True; HOURLYUPTREND = False; end; //Buy condition If HOURLYUPTREND then Buy 1 contract next bar market; Print((SMA20H - SMA10H)); If HOURLYDOWNTREND then SellShort 1 contract next bar market; Print((SMA10H - SMA20H));
-
- Posts: 5
- Joined: 12 Jun 2023
Re: Problem with data2 [SOLVED]
Hi ABC,
Thank you very much! It's now working
Very greatful for the help, thank you so much!
Best regards
Thank you very much! It's now working
Very greatful for the help, thank you so much!
Best regards