outofdebt:
I need some help to account for weekend time. I am writing a script that keeps track of time trades are open. However, no matter what I can't figure out the code to make it subtract the 'weekend time' from the total time that trades are open.
Help! Any ideas?
Here is the code I am working with:
Try it code.
extern int TimeStartModay = 0; //Time to start trade moday extern int TimeStopFriday = 23; //Time to stop trade friday bool RunIndicators; int start() { RunIndicators=true; if(((DayOfWeek()==1)&&(TimeHour(TimeCurrent())>=TimeStartModay))||((DayOfWeek()==5)&&(TimeHour(TimeCurrent())<=TimeStopFriday))) RunIndicators=false; ....... return(0); }
outofdebt:
I need some help to account for weekend time. I am writing a script that keeps track of time trades are open.
I need some help to account for weekend time. I am writing a script that keeps track of time trades are open.
for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. ){ datetime OOT = OrderOpenTime(); int duration = TimeCurrent() - OOT, hours = duration / 3600, mins = duration % 3600 / 60; Print("Order ", OrderTicket(), "open for ", hours, ":", mins, "total"); int iBar = iBarShift(NULL,0, OOT), secPer = Period() * 60; duration = (TimeCurrent() - Time[0]) // Time current bar. - (OOT - Time[iBar]) // Before open, open bar. + iBar * secPer // Completed bars. hours = duration / 3600, mins = duration % 3600 / 60; Print("Order ", OrderTicket(), "open for ", hours, ":", mins, "excluding weekends and holidays"); break; }
WHRoeder:
Thanks, I am using this script on orders generated in the strategy tester. How would I go about modifying your code to work in that situation?
ok, i figured it out. The variables I was using were referencing the the 1 min timeframe because they are used in another calculation. I created separate vars for the
open and close bar that use the timeframe of the chart that is being backtested, and it picks up the correct weekend time and subtracts from total time as needed.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I need some help to account for weekend time. I am writing a script that keeps track of time trades are open. However, no matter what I can't figure out the code to make it subtract the 'weekend time' from the total time that trades are open.
Help! Any ideas?
Here is the code I am working with: