I want to buy at 0300am and C>ma25 , then sell at 04:00
But duno why even I simply write Buy= timenum()=030000; also can't show the Buy Signal.
Am my logic wrong?
Plot( C, "Price", colorDefault, styleCandle );
time=TimeNum();
MA25=ma(C,25);
Plot(MA25, "MA25", colorBlue, styleLine | styleThick);
Buy = time==030000 AND Close>MA25 ;
// Sell condition: Exit long position at 6:00 AM
Sell = time==040000;
// Short condition: Close < MA5 at 3:00 AM
Short = time==030000 AND Close<MA25 ;
// Cover condition: Exit short position at 6:00 AM
Cover = time==040000;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
PlotShapes(IIf(Buy, shapeuparrow, shapeNone),colorTurquoise, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapedowntriangle, shapeNone),Colorcustom12, 0, H, Offset=-60);
PlotShapes(IIf(Cover, shapeuptriangle, shapenone),colorTurquoise, 0, L , Offset=-65);
PlotShapes(IIf(Short, shapedownarrow, shapeNone),Colorcustom12, 0,H, Offset=-40);
Your code works fine. Make sure your chart time is set to 1-hour or less so 3am is triggered.
I am using 24Hours View and 15-Min chart but no signal showed, would you mind teach me how to make it show my wanted chart ?
Many Thanks!
Hmm, that's odd. This is what I get with your script for 15-min EURUSD:
Oh...my god....would you mind tell me what's your Amibroker version?
EURUSD Seems not bad to trade
you need to check in the interpretation window if it is working. Because the precise time possibly is not there. Not sure what could cause that. Maybe your database settings, intraday time settings. Not sure if that can influence it. But you can easily check using the interpretation window.
test1:
time = TimeNum();
Buy1 = time == 030000;
"buy1: " + Buy1;
when you move with the cursor of the mouse to 03000 and click on that time you should see Buy1: 1
If you do not see that you could try test 2
test2:
time = TimeNum();
Buy2 = time >= 030000;
Buy2 = ( Buy2 - Ref( Buy2, -1 ) ) == 1;
"buy2: " + Buy2;
1 Like
Buy1:0
Buy2:1
what does it mean? thanks!
It means you don't have any bar with the timestamp 3:00:00. Maybe it's 2:59:59 or something similar. Check your Quote Editor window to see what the actual timestamps on your data are, and then make sure your intraday settings are set accordingly.
2 Likes
if you put the mouse cursor on 030000 and Buy1 show 0 (zero) then .... ah see the answer of @mradtke appearing. Like he says apparently you do not have that exact time. In this case you could use:
time = TimeNum();
Buy2 = time >= 030000;
Buy = ( Buy2 - Ref( Buy2, -1 ) ) == 1 and C > MA25;
2 Likes
Plot( C, "Price", colorDefault, styleCandle );
time=TimeNum();
MA25=ma(C,25);
Plot(MA25, "MA25", colorBlue, styleLine | styleThick);
Buy = Ref(time, -1) < 030000 AND time >= 030000 AND Close>MA25 ;
// Sell condition: Exit long position at 6:00 AM
Sell = Ref(time, -1) < 040000 AND time >= 040000;
// Short condition: Close < MA5 at 3:00 AM
Short = Ref(time, -1) < 030000 AND time >= 030000 AND Close<MA25 ;
// Cover condition: Exit short position at 6:00 AM
Cover = Ref(time, -1) < 040000 AND time >= 040000;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
PlotShapes(IIf(Buy, shapeuparrow, shapeNone),colorTurquoise, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapedowntriangle, shapeNone),Colorcustom12, 0, H, Offset=-60);
PlotShapes(IIf(Cover, shapeuptriangle, shapenone),colorTurquoise, 0, L , Offset=-65);
PlotShapes(IIf(Short, shapedownarrow, shapeNone),Colorcustom12, 0,H, Offset=-40);
1 Like