Download MetaTrader 5
To add comments, please log in or register
MQL5 library has more than 1500 apps already. Contribute your own one!
MetaQuotes Software Corp.
Moderator
180322
MetaQuotes Software Corp. 2011.11.11 09:22 

psar bug 7:

Opens and closes orders using parabolic sar signals.

Author: Tonny Obare

Tjipke de Vries
6298
Tjipke de Vries 2011.11.14 10:30  
int    digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){StopMultd=10;} else{StopMultd=1;}

There are a lot of accounts with added to the currency a prefix or suffix. In that case......

int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,NormalizeDouble(Ask-SL*Point,Digits),NormalizeDouble(Ask+TP*Point,Digits),"psar bug 6 order ",MagicNumber);//Opening Buy
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,NormalizeDouble(Bid+SL*Point,Digits),NormalizeDouble(Bid-TP*Point,Digits),"psar bug 6 order ",MagicNumber);//Opening Sell

Still no coding for working on ECN accounts

//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==MagicNumber) {int halt1=1;}
        }
     }
}

Why not selecting on OrderSymbol and OrderMagicnumber...

With trailing you're not selecting the OrderMagicNumber....

ONLY GOOD FOR BACKTESTING ......

Tonny Obare
1018
Tonny Obare 2011.11.14 13:58  
deVries:
int    digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){StopMultd=10;} else{StopMultd=1;}

There are a lot of accounts with added to the currency a prefix or suffix. In that case......

int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,NormalizeDouble(Ask-SL*Point,Digits),NormalizeDouble(Ask+TP*Point,Digits),"psar bug 6 order ",MagicNumber);//Opening Buy
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,NormalizeDouble(Bid+SL*Point,Digits),NormalizeDouble(Bid-TP*Point,Digits),"psar bug 6 order ",MagicNumber);//Opening Sell

Still no coding for working on ECN accounts

//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==MagicNumber) {int halt1=1;}
        }
     }
}

Why not selecting on OrderSymbol and OrderMagicnumber...

With trailing you're not selecting the OrderMagicNumber....

ONLY GOOD FOR BACKTESTING ......

Attention all users! This expert advisor of mine of which i have worked hard to provide 100% free is provided as is and free things cant always satisfy personal requirements of everyone. Happy now :-) anyway to get serious im stopping further development on psar bug to concentrate on xbug and our premium scripts. For any other custom modifications please contact me i send you a quote but this is pretty much the last or second last psar bug.
Tonny Obare
1018
Tonny Obare 2011.11.14 14:16  
devries you also might wana read the full psar bug documentation http://www.fxautomated.com/docs/psarbugdoc.php to understand this EA better. The magic number is editable by the user making it more flexible thus its enough to only select magic number only and not ordersymbol too since on different charts, timeframes etc the user can set a different magic number afterall thats the work of magic number otherwise i would'nt have made it editable on the user side.
Tjipke de Vries
6298
Tjipke de Vries 2011.11.14 15:10  
tonny:
devries you also might wana read the full psar bug documentation https://www.mql5.com/go?http://www.fxautomated.com/docs/psarbugdoc.php to understand this EA better. The magic number is editable by the user making it more flexible thus its enough to only select magic number only and not ordersymbol too since on different charts, timeframes etc the user can set a different magic number afterall thats the work of magic number otherwise i would'nt have made it editable on the user side.

if((Trailing==true)&&(OrdersTotal()>0)){
//-----------------------------------------------------------------------------------------------------------------------
// Trail
/*-----------------------------------------------------------------------------------------------------------------------*/
string Symb=Symbol();                        // Symbol
//------------------------------------------------------------------------------- 2 --
   for(i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type
         if(OrderSymbol()!=Symb||Tip>1)continue;// The order is not "ours"
         double SLt=OrderStopLoss();             // SL of the selected order
         //---------------------------------------------------------------------- 3 --
         while(true)                            // Modification cycle
           {
            double TS=Tral_Stop;                // Initial value
            int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);//Min. distance
            if (TS < Min_Dist)                  // If less than allowed
               TS=Min_Dist;                     // New value of TS
            //------------------------------------------------------------------- 4 --
            bool Modify=false;                  // Not to be modified
            switch(Tip)                         // By order type
              {
               case 0 :                         // Order Buy
                  if (NormalizeDouble(SLt,Digits)< // If it is lower than we want
                     NormalizeDouble(Bid-TS*Point,Digits))
                    {
                     SLt=Bid-TS*Point;           // then modify it
                     string Text="Buy ";        // Text for Buy 
                     Modify=true;               // To be modified
                    }
                  break;                        // Exit 'switch'
               case 1 :                         // Order Sell
                  if (NormalizeDouble(SLt,Digits)> // If it is higher than we want
                     NormalizeDouble(Ask+TS*Point,Digits)
                     || NormalizeDouble(SLt,Digits)==0)//or equal to zero
                    {
                     SLt=Ask+TS*Point;           // then modify it
                     Text="Sell ";              // Text for Sell 
                     Modify=true;               // To be modified
                    }
              }                                 // End of 'switch'
            if (Modify==false)                  // If it is not modified
               break;                           // Exit 'while'
            //------------------------------------------------------------------- 5 --
            double TPt    =OrderTakeProfit();    // TP of the selected order
            double Price =OrderOpenPrice();     // Price of the selected order
            int    Ticket=OrderTicket();        // Ticket of the selected order
            Alert ("Modification ",Text,Ticket,". Awaiting response..");
            bool Ans=OrderModify(Ticket,Price,SLt,TPt,0);//Modify it!
            //------------------------------------------------------------------- 6 --
            if (Ans==true)                      // Got it! :)
              {
               Alert ("Order ",Text,Ticket," is modified:)");
               break;                           // From modification cycle.
              }
            //------------------------------------------------------------------- 7 --
            break;
           }                                   // End of modification cycle
         //---------------------------------------------------------------------- 8 --
        }                                       // End of order analysis
     }                                          // End of order search
//------------------------------------------------------------------------------- 9 --
            int Error=GetLastError();           // Failed :(
            switch(Error)                       // Overcomable errors
              {
               case 130:Alert("Wrong stops. Retrying.");
                  RefreshRates();               // Update data
                                      // At the next iteration
               case 136:Alert("No prices. Waiting for a new tick..");
                  while(RefreshRates()==false)  // To the new tick
                     Sleep(1);                  // Cycle delay
                                      // At the next iteration
               case 146:Alert("Trading subsystem is busy. Retrying ");
                  Sleep(500);                   // Simple solution
                  RefreshRates();               // Update data
                                      // At the next iteration
                  // Critical errors
               case 2 : Alert("Common error.");
                                         // Exit 'switch'
               case 5 : Alert("Old version of the client terminal.");
                                        // Exit 'switch'
               case 64: Alert("Account is blocked.");
                                        // Exit 'switch'
               case 133:Alert("Trading is prohibited");
                                         // Exit 'switch'
               default: Alert("Occurred error ",Error);//Other errors
              }
                                       // From modification cycle
//------------------------------------------------------------------------------------------------------------------------
// end trail
//--------------------------------------------------------------------------------------------------------------------------
}
But if you read this code your EA your not selecting Magicnumber with trailing. In this case trades of same currencie found in your orderselect with another magicnumber will be modified by the rules of this EA.... Trie it out if you don't believe me....
MQL4 Comments
16319
MQL4 Comments 2011.11.14 22:22  
Hello Tonny,

Unable to get Psar Bug 7 to work without Manual Confirmation.

My Sar settings match in EA and indicator (Step .03, Max .2)

On platform, Tools ---> Options ---> Unchecked 'Manual Confirmation'

What am I doing wrong?

Thank you.
MQL4 Comments
16319
MQL4 Comments 2011.11.14 22:32  

...cont'd

P.S. I am on a 5-Digit Broker

Tonny Obare
1018
Tonny Obare 2011.11.15 09:38  
FXSysssr:
Hello Tonny,

Unable to get Psar Bug 7 to work without Manual Confirmation.

My Sar settings match in EA and indicator (Step .03, Max .2)

On platform, Tools ---> Options ---> Unchecked 'Manual Confirmation'

What am I doing wrong?

Thank you.

When you attach the ea and the settings dialogue appears there is a tab called "common" this tab also has settings for live trading and manual confirmation please check if "allow live trading" is checked and "ask manual confirmation" should be unchecked.
Tonny Obare
1018
Tonny Obare 2011.11.15 09:43  
deVries:
tonny:
devries you also might wana read the full psar bug documentation https://www.mql5.com/go?http://www.fxautomated.com/docs/psarbugdoc.php to understand this EA better. The magic number is editable by the user making it more flexible thus its enough to only select magic number only and not ordersymbol too since on different charts, timeframes etc the user can set a different magic number afterall thats the work of magic number otherwise i would'nt have made it editable on the user side.

if((Trailing==true)&&(OrdersTotal()>0)){
//-----------------------------------------------------------------------------------------------------------------------
// Trail
/*-----------------------------------------------------------------------------------------------------------------------*/
string Symb=Symbol();                        // Symbol
//------------------------------------------------------------------------------- 2 --
   for(i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type
         if(OrderSymbol()!=Symb||Tip>1)continue;// The order is not "ours"
         double SLt=OrderStopLoss();             // SL of the selected order
         //---------------------------------------------------------------------- 3 --
         while(true)                            // Modification cycle
           {
            double TS=Tral_Stop;                // Initial value
            int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);//Min. distance
            if (TS < Min_Dist)                  // If less than allowed
               TS=Min_Dist;                     // New value of TS
            //------------------------------------------------------------------- 4 --
            bool Modify=false;                  // Not to be modified
            switch(Tip)                         // By order type
              {
               case 0 :                         // Order Buy
                  if (NormalizeDouble(SLt,Digits)< // If it is lower than we want
                     NormalizeDouble(Bid-TS*Point,Digits))
                    {
                     SLt=Bid-TS*Point;           // then modify it
                     string Text="Buy ";        // Text for Buy 
                     Modify=true;               // To be modified
                    }
                  break;                        // Exit 'switch'
               case 1 :                         // Order Sell
                  if (NormalizeDouble(SLt,Digits)> // If it is higher than we want
                     NormalizeDouble(Ask+TS*Point,Digits)
                     || NormalizeDouble(SLt,Digits)==0)//or equal to zero
                    {
                     SLt=Ask+TS*Point;           // then modify it
                     Text="Sell ";              // Text for Sell 
                     Modify=true;               // To be modified
                    }
              }                                 // End of 'switch'
            if (Modify==false)                  // If it is not modified
               break;                           // Exit 'while'
            //------------------------------------------------------------------- 5 --
            double TPt    =OrderTakeProfit();    // TP of the selected order
            double Price =OrderOpenPrice();     // Price of the selected order
            int    Ticket=OrderTicket();        // Ticket of the selected order
            Alert ("Modification ",Text,Ticket,". Awaiting response..");
            bool Ans=OrderModify(Ticket,Price,SLt,TPt,0);//Modify it!
            //------------------------------------------------------------------- 6 --
            if (Ans==true)                      // Got it! :)
              {
               Alert ("Order ",Text,Ticket," is modified:)");
               break;                           // From modification cycle.
              }
            //------------------------------------------------------------------- 7 --
            break;
           }                                   // End of modification cycle
         //---------------------------------------------------------------------- 8 --
        }                                       // End of order analysis
     }                                          // End of order search
//------------------------------------------------------------------------------- 9 --
            int Error=GetLastError();           // Failed :(
            switch(Error)                       // Overcomable errors
              {
               case 130:Alert("Wrong stops. Retrying.");
                  RefreshRates();               // Update data
                                      // At the next iteration
               case 136:Alert("No prices. Waiting for a new tick..");
                  while(RefreshRates()==false)  // To the new tick
                     Sleep(1);                  // Cycle delay
                                      // At the next iteration
               case 146:Alert("Trading subsystem is busy. Retrying ");
                  Sleep(500);                   // Simple solution
                  RefreshRates();               // Update data
                                      // At the next iteration
                  // Critical errors
               case 2 : Alert("Common error.");
                                         // Exit 'switch'
               case 5 : Alert("Old version of the client terminal.");
                                        // Exit 'switch'
               case 64: Alert("Account is blocked.");
                                        // Exit 'switch'
               case 133:Alert("Trading is prohibited");
                                         // Exit 'switch'
               default: Alert("Occurred error ",Error);//Other errors
              }
                                       // From modification cycle
//------------------------------------------------------------------------------------------------------------------------
// end trail
//--------------------------------------------------------------------------------------------------------------------------
}
But if you read this code your EA your not selecting Magicnumber with trailing. In this case trades of same currencie found in your orderselect with another magicnumber will be modified by the rules of this EA.... Trie it out if you don't believe me....

Actually this ea works better without trailing i just added it there as an option because of a user requested it and this is why i prefer handling personal customisations separately.
MQL4 Comments
16319
MQL4 Comments 2011.11.15 09:51  

Hi Tonny,

Yes, under 'Common Tab' I have 'Live Trading' checked and 'Manual Confirmation' unchecked.

I tested it on the 1M and 5M GBP/USD charts, no orders are opening automatically, no error messages in Journal.

Works perfectly with Manual Confirmation though. Any other suggestions, please let me know...

Thanks

tonny:
FXSysssr:
Hello Tonny,

Unable to get Psar Bug 7 to work without Manual Confirmation.

My Sar settings match in EA and indicator (Step .03, Max .2)

On platform, Tools ---> Options ---> Unchecked 'Manual Confirmation'

What am I doing wrong?

Thank you.

When you attach the ea and the settings dialogue appears there is a tab called "common" this tab also has settings for live trading and manual confirmation please check if "allow live trading" is checked and "ask manual confirmation" should be unchecked.

Tonny Obare
1018
Tonny Obare 2011.11.15 10:30  
FXSysssr:

Hi Tonny,

Yes, under 'Common Tab' I have 'Live Trading' checked and 'Manual Confirmation' unchecked.

I tested it on the 1M and 5M GBP/USD charts, no orders are opening automatically, no error messages in Journal.

Works perfectly with Manual Confirmation though. Any other suggestions, please let me know...

Thanks

tonny:
FXSysssr:
Hello Tonny,

Unable to get Psar Bug 7 to work without Manual Confirmation.

My Sar settings match in EA and indicator (Step .03, Max .2)

On platform, Tools ---> Options ---> Unchecked 'Manual Confirmation'

What am I doing wrong?

Thank you.

When you attach the ea and the settings dialogue appears there is a tab called "common" this tab also has settings for live trading and manual confirmation please check if "allow live trading" is checked and "ask manual confirmation" should be unchecked.



Confirmation of trade operations is built in mt4 not EAs. Try uninstalling and reinstalling your meta trader.
/ /12
To add comments, please log in or register