Easier Way? Universal Weekend() without DLL

 

I just re-wrote my old weekend function. I'm trying to make it more universal without using DLL for time issues. It's your typical Weekending and Weekend Gap function. I'm wondering if anyone have an easier way of doing this without dlls?

Issues to consider.

1) Some brokers week starts on Wednesday so i cannot use Period_W1 because I need that Monday Open Gap.

2) Some brokers are opened 6-days a week (this usually includes Sunday-Friday) instead of 5.

Here's the code I just wrote. I haven't tested this version on Fxdd vs Forexite data however previous versions have been.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~WeekEnd-Variables:
int     Gap, Gap_TimeStamp, Week_Ending, Day1;
double  End_Price;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int start(){//Start-Function:###############################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Weekend(iSymbol);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return(0);}//End_Of_Start():################################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~User_Defined-Functions:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~Weekend_Gap-Function:
int Weekend(string iSymbol){
    int TC, Today, Day_1=1, Hrs_inWeek=170, End_Time; Ans=0;
    //~~~~~~~~~~
    if(iBars(iSymbol,PERIOD_H1)<Hrs_inWeek){
        Inform("Theres Not Enough H1-Bars to Perform Weekend Calculations",3);
        Inform("Switching Trade_Mode to OFF, Download H1_Bars & Switch-On",3);
        Mode=0; return(Ans);
    }
    //~~~~~~~~~~
    for(i=Hrs_inWeek;i>=0;i--){
        if( TimeDayOfWeek(iTime(iSymbol,PERIOD_H1,i) )==0 ){
            Day_1=0; Inform("This Brokers Week Starts on Sunday Instead of Monday",1);
        }
    }
    //~~~~~~~~~~
    TC=TimeCurrent(); Today=TimeDayOfWeek(TC);
    if(Today==5 && Hour()>=16 && Week_Ending==0){
        Week_Ending=1; Inform("The Week is Ending, Reminder for WeekEnd Strategies",1);
    }
    if(Today==Day1 && TC>Gap_TimeStamp+iHour*119){
        Gap_TimeStamp=0;Week_Ending=0;
        Inform("Its The Begining of a New Week, Reset Some Variables",1);
    }
    //~~~~~~~~~~
    End_Time=iTime(iSymbol,PERIOD_M5,1);
    if(Gap_TimeStamp==0 && Today==Day1 && TimeDayOfWeek(End_Time)!=Today){
        if(MathAbs(iClose(iSymbol,PERIOD_M5,1)-iOpen(iSymbol,PERIOD_M5,0))>1*Point2Pip){
            End_Price=iClose(iSymbol,PERIOD_M5,1);
            if(iClose(iSymbol,PERIOD_M5,1)<iOpen(iSymbol,PERIOD_M5,0)){
                Gap=-1; Inform("A Bearish-\/- Weekend_Gap have been Established",1);
                Gap_TimeStamp=TimeCurrent();
            }else{
                Gap= 1; Inform("A Bullish-/\- Weekend_Gap have been Established",1);
                Gap_TimeStamp=TimeCurrent();
            }
        }
    }
    //~~~~~~~~~~
    if((Gap==1 && Ask>End_Price) 
        || (Gap==-1 && Bid<End_Price)
            || TimeCurrent()>Gap_TimeStamp+iHour*23){
                Gap=0; Inform("The Gap has Out-Lived its Usefulness in Some Way",1);
    }
    //~~~~~~~~~~
return(Gap);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
if(MathAbs(iClose(iSymbol,PERIOD_M5,1)-iOpen(iSymbol,PERIOD_M5,0))>1*Point2Pip){
You want 1*Pip2double there. if(0.0005 > 1*10) makes no sense
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 
WHRoeder:
You want 1*Pip2double there. if(0.0005 > 1*10) makes no sense



I use a lightly different convention then yours. And have been using it for a long time now. I prefer it just as a matter of how my brain works. Here's my function for 5 digit brokers.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~Declear-Variables:
string  iSymbol, iMessage;
//~~~~~~~~~~
int     Pip2Real=10000, iValue=10;
//~~~~~~~~~~
double  Point2Pip;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~Init-Function:
int init(){
//~~~~~~~~~~
    //~~~~~~~~~~MarketInfo:
    iSymbol=Symbol(); Market_Info(iSymbol);
    //~~~~~~~~~~Point2Pip:
    Point2Pip=Point; if(Digits==2 || Digits==3){Pip2Real=100;}
    if(Digits==3){Point2Pip=0.01;}if(Digits==5){Point2Pip=0.0001;}
//~~~~~~~~~~
return(0);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think of Pip now-a-days as 0.0001, so calling it Pip2Double confuses me :) because Pip is already a Double Value to me. What I'm asking for is if the difference is > than 1 Pip if(0.0005 > 1*0.0001). I started using 1*Point2Pip since the Error#1 thread. And I still don't get why I had to multiply by 1 then or now. Except for it's some crazy C/C++ world where 0.0001 is not equal to 1*0.0001. Or int 0, is not equal to double 0.0. It only makes sense to me from a bit-wise prospective.

Looking at it as Point2Pip also helps me in examples where StopLoss=30. I can just say OrderOpenPrice-StopLoss*Point2Pip.

For Slippage, if I'm feeling lazy, I use Mode_Spread. I have a fixed spread broker so that don't hurt me. Now that I'm trying to write for others whose Spreads could fluctuate wildly. I intend to use my good old variable iValue as the multiple for 5-Digits brokers and leave it as is for 4-Digits. That variable never changes anyways.

I use Pip2Real to Comment() stuff like how much Volatility is currently in Pips in Integer Value. And use that as StopLoss or something. And vice-versa for how much StopLoss there is and use that in Money Management or something.

 

Ok, I've settled on this version. Works on Fxdd vs Forexite Historical Data.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~Weekend_Gap-Function:
int Weekend(string iSymbol){
    int TC, Today, Hrs_inWeek=170, End_Time; Ans=0;
    //~~~~~~~~~~
    if(iBars(iSymbol,PERIOD_H1)<Hrs_inWeek){
        Inform("Theres Not Enough H1-Bars to Perform Weekend Calculations",3);
        Inform("Switching Trade_Mode to OFF, Download H1_Bars & Switch-On",3);
        Mode=0; return(Ans);
    }
    //~~~~~~~~~~
    if(GlobalVariableGet("Set_1st")==0){
        for(i=Hrs_inWeek;i>=0;i--){
            if( TimeDayOfWeek(iTime(iSymbol,PERIOD_H1,i) )==0 ){
                Day1=0; Inform("This Brokers Week Starts on Sunday Instead of Monday",1);
            }
            if(i==0){GlobalVariableSet("Set_1st",1);}
        }
    }
    //~~~~~~~~~~
    TC=TimeCurrent(); Today=TimeDayOfWeek(TC);
    if(Today==5 && Hour()>=16 && Week_Ending==0){
        Week_Ending=1; Inform("The Week is Ending, Reminder for WeekEnd Strategies",1);
    }
    if(Today==Day1 && TC>Gap_TimeStamp+iHour*119){
        Gap_TimeStamp=0;Week_Ending=0;
        Inform("Its The Begining of a New Week, Reset Some Variables",1);
    }
    //~~~~~~~~~~
    End_Time=iTime(iSymbol,PERIOD_M5,1);
    if(Gap_TimeStamp==0 && Today==Day1 && TimeDayOfWeek(End_Time)!=Today){
        if(MathAbs(iClose(iSymbol,PERIOD_M5,1)-iOpen(iSymbol,PERIOD_M5,0))>1*Point2Pip){
            End_Price=iClose(iSymbol,PERIOD_M5,1);
            if(iClose(iSymbol,PERIOD_M5,1)<iOpen(iSymbol,PERIOD_M5,0)){
                Gap=-1; Inform("A Bearish-\/- Weekend_Gap have been Established",1);
                Gap_TimeStamp=TimeCurrent();
            }else{
                Gap= 1; Inform("A Bullish-/\- Weekend_Gap have been Established",1);
                Gap_TimeStamp=TimeCurrent();
            }
        }
    }
    //~~~~~~~~~~
    if((Gap==1 && Ask>End_Price)
        || (Gap==-1 && Bid<End_Price)
            || TimeCurrent()>Gap_TimeStamp+iHour*23 && Gap!=0){
                Gap=0; Inform("The Gap has Out-Lived its Usefulness in Some Way",1);
    }
    //~~~~~~~~~~
return(Gap);}
 
ubzen:
I use a lightly different convention then yours. And have been using it for a long time now. I prefer it just as a matter of how my brain works. Here's my function for 5 digit brokers.
I think of Pip now-a-days as 0.0001, so calling it Pip2Double confuses me :) because Pip is already a Double Value to me. What I'm asking for is if the difference is > than 1 Pip if(0.0005 > 1*0.0001).

Different conventions are fine. If you want to compare price difference to 2 pips you'd compare to 0.0002 (either 2*Point or 20*Point depending on the broker.)

If you want slippage as 2 pips then you need either 2 or 20 depending on the broker (OrderSend slippage is units of points. )

Same word 'pips', two different contexts price or points. Thus I use pips2dbl (or pips2price if you like) and pips2points.

 

...(or pips2price if you like)...

Pip2Price, I like that. Perhaps that's what I should have called-it instead (less-confusing-others). Thinking of that Epic point-pip post lol. I'm sure 90% of us have different names for what that 4-5 broker converter is called. I must say tho.. yours must be the most popular by now :). Part of me just don't like directly copying others and that could be another reason I choose a different name and didn't do any arithmetic in my version.

Reason: