stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Old and defunct Holy Graily Bob
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3966
Page 26 of 129
Author:  4xtn [ Mon Dec 08, 2014 1:25 am ]
Post subject:  Holy Graily Bob

How about pending orders, but with user defined distance from PA?
Author:  BobbyT [ Mon Dec 08, 2014 2:52 am ]
Post subject:  Holy Graily Bob

I haven't looked at the code at all (so not sure if this is incorporated already) but maybe try using

Code: Select all

 MarketInfo(NULL,MODE_STOPLEVEL) 
in the calculations for where to place the first pending positions.
This way, broker specific stop levels can be autodetected and be dynamic within the code. It is also a one solution fits all brokers type situation once implemented.
I have a snippet at home that I used some time ago to ensure trades were beyond the stop level, but I'm at work at the moment. If your interested I can find it later though I'm sure you've either already thought of this or could conjure your own snippet anyway.

Cheers,
BobbyT
Author:  oliverjp [ Mon Dec 08, 2014 7:56 am ]
Post subject:  Holy Graily Bob

Hi

I've had problems like this in the past when coding a news trader that tried to slip in orders just before news time when the prices and spreads went crazy and pending trades wouldn't take. I made my order placement code cycle through increasing stop loss values until it managed to place the order or it reached my maximum. I found half a pip extra each time and a maximum of 5 extra pips (so max 10 iterations) worked OK for that application.

Best regards

Jeff


SteveHopwood » Sun Dec 07, 2014 11:34 pm wrote:Ok, unlocking this thread.

Please do not post about failed trade sends. We know about them.

Trust me, I do not mean 'please'. You will not enjoy the result of posting another failed trade send.

Anybody here go any solutions?

:xm:
Author:  oliverjp [ Mon Dec 08, 2014 8:10 am ]
Post subject:  Holy Graily Bob

Here you go, found an early variant of the code I wrote that did it. Sorry, can't find the later more polished version:

Code: Select all

//+------------------------------------------------------------------+
//| Initisl StopLoss                                             |
//+------------------------------------------------------------------+
void InitialStopLoss()
{
   int    Total, Ticket, retry;
   int    SLretries = 20;  
   double StopLoss;

   Total = OrdersTotal();

   for(int i = 0; i < Total; i++)
     {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))  
       {
       if (OrderSymbol() == ThisSymbol && OrderMagicNumber() == MagicNumber && TP1_Closed == FALSE && OrderStopLoss() == 0)
         {         
         if (OrderType() == OP_BUY)            //  Buy side processing
           {
           RefreshRates();
           StopLoss = NormalizeDouble(OrderOpenPrice() - (EntryToTP1_StopLossPips * Point * 10),Digits);                        
           if (OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,0,0,Red))
             { 
             Ticket = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
             Print("StopLoss set by InitialStopLoss to: ",OrderStopLoss());
             InitialSLSet = TRUE;
             }
           else  // Attempt to set SL failed - try harder half a pip further out each attempt
             {
             for (retry=1; retry<SLretries; retry++)
               {
               RefreshRates();
               StopLoss = NormalizeDouble(OrderOpenPrice() - ((EntryToTP1_StopLossPips + (0.5 * retry)) * Point * 10),Digits);                        
               if (OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,0,0,Red))
                 {
                 Ticket = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
                 Print("StopLoss set by InitialStopLoss DYNAMIC to: ",OrderStopLoss(), "   Needed ",retry/2," extra pips.");
                 InitialSLSet = TRUE;
                 break;
                 }
               }
             }
           
           if (InitialSLSet == FALSE)
             {           
             if (OrderClose(OrderTicket(),OrderLots(),Bid,500,Red))  Print("InitialStopLoss KILLED Buy order as Initial SL could not be set!");
             else Print(strModifyError,GetLastError(),"   WARNING! - InitialStopLoss FAILED TO KILL Buy order when SL could not be set!");
             }
           }             
                   
         else if  (OrderType() == OP_SELL)           // Sell side processing
           {
           RefreshRates();
           StopLoss = NormalizeDouble(OrderOpenPrice() + (EntryToTP1_StopLossPips * Point * 10),Digits);                        
           if (OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,0,0,Red))
             {
             Ticket = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
             Print("StopLoss set by InitialStopLoss to: ",OrderStopLoss());
             InitialSLSet = TRUE;
             }
           else  // Attempt to set SL failed - try harder half a pip further out each attempt
             {
             for (retry=1; retry<SLretries; retry++)
               {
               RefreshRates();
               StopLoss = NormalizeDouble(OrderOpenPrice() + ((EntryToTP1_StopLossPips + (0.5 * retry)) * Point * 10),Digits);                        
               if (OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,0,0,Red))
                 {
                 Ticket = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
                 Print("StopLoss set by InitialStopLoss DYNAMIC to: ",OrderStopLoss(), "   Needed ",retry/2," extra pips.");
                 InitialSLSet = TRUE;
                 break;
                 }
               }
             }
           if (InitialSLSet == FALSE)
             {           
             if (OrderClose(OrderTicket(),OrderLots(),Bid,500,Red))  Print("InitialStopLoss KILLED Sell order as Initial SL could not be set!");
             else Print(strModifyError,GetLastError(),"   WARNING! - InitialStopLoss FAILED TO KILL Sell order when SL could not be set!");
             }
           }
         }  
       }
     }
                  
return;
}

oliverjp » Mon Dec 08, 2014 7:56 am wrote:Hi

I've had problems like this in the past when coding a news trader that tried to slip in orders just before news time when the prices and spreads went crazy and pending trades wouldn't take. I made my order placement code cycle through increasing stop loss values until it managed to place the order or it reached my maximum. I found half a pip extra each time and a maximum of 5 extra pips (so max 10 iterations) worked OK for that application.

Best regards

Jeff


SteveHopwood » Sun Dec 07, 2014 11:34 pm wrote:Ok, unlocking this thread.

Please do not post about failed trade sends. We know about them.

Trust me, I do not mean 'please'. You will not enjoy the result of posting another failed trade send.

Anybody here go any solutions?

:xm:
Author:  BritShrtHair [ Mon Dec 08, 2014 8:34 am ]
Post subject:  Holy Graily Bob

SteveHopwood » Sun Dec 07, 2014 11:34 pm wrote:Ok, unlocking this thread.
Anybody here go any solutions?
in HGB, when replacing line 1878 (void LookForTradingOpportunities())

Code: Select all

double SendLots = 0;
with

Code: Select all

double SendLots = MarketInfo(Symbol(),MODE_MINLOT);
HGB seems to start taking trades again.
Thats seems to be (one of the?) culprits.
Author:  SteveHopwood [ Mon Dec 08, 2014 9:37 am ]
Post subject:  Holy Graily Bob

V 1l is in post 1.

Thanks guys. You put me on the right track.

You know how these problems are usually copy/paste/fail-to-edit bloops? This time they were copy-but-didn't-quite-copy-enough/paste/edit bloops.

HGB is taking the pending trades now.

:xm:
Author:  SteveHopwood [ Mon Dec 08, 2014 9:55 am ]
Post subject:  Holy Graily Bob

Don't bother downloading 1L folks. Still isn't right.

:xm:
Author:  BobbyT [ Mon Dec 08, 2014 10:07 am ]
Post subject:  Holy Graily Bob

Lucky I decided to have dinner before upating :smile:
Author:  SteveHopwood [ Mon Dec 08, 2014 10:33 am ]
Post subject:  Holy Graily Bob

V 1m is in post 1. We appear to be fully functional now, but take nothing for granted. :arrrg:

:xm:
Author:  Lee [ Mon Dec 08, 2014 11:03 am ]
Post subject:  Holy Graily Bob

SteveHopwood » Mon Dec 08, 2014 10:33 am wrote:V 1m is in post 1. We appear to be fully functional now, but take nothing for granted. :arrrg:

:xm:
Steve,

Thanks for your brilliant work. The highlighted line I believe should read 'RAD trade multiple positions' instead of 'Trend'? Just to avoid confusion.

Lee
All times are UTC Page 26 of 129