Jump to content

Building your own EA G/08.


asgard2

Recommended Posts

  • Replies 189
  • Created
  • Last Reply

Top Posters In This Topic

Re: Building your own EA G/08.

 

I'm still wading through the greezly code. It seems that there are huge blocks of code that can be completely removed since we are not using instant execution trades, as well as a number of externs that relate to them.

 

I think I will keep all the code in anyway, and use an extern bool to filter out these code blocks.

 

My code is heavily commented in English now (after removing all the russian comments that don't encode properly anyway), and I have a better idea of what's going on.

Slowly Slowly catchy monkey....

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Just curious.... with OP_BUYSTOP and OP_SELLSTOP trades... do they change modes to OP_BUY and OP_SELL once they are executed and opened by the terminal?

 

I aslo has a quick look at GEPARD now knowing what I do about the functions in Greezley ... indeed there are some almost identical routines, but they are slightly different. My effort there is not helped by the fact that the GEPARD code variables are all numbered. I'm thinking about how to incorporate the gepard parts into the Greezely code... but that will have to wait until I manage to fix some of the other bits first.

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Ok.. this drop happened the day before the NFP.. I have a dojie rule that prevented this happening.. so lucky

 

I'm not quite following your stop-loss approach. Earlier you said it works on "reverse logic + percentage".

 

Do you mean you look for the opposite conditions that signal a buy and close the trade if this happens?

 

So those trades were closed at a loss in that image, correct?

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

 

I'm not quite following your stop-loss approach. Earlier you said it works on "reverse logic + percentage".

 

Do you mean you look for the opposite conditions that signal a buy and close the trade if this happens?

 

So those trades were closed at a loss in that image, correct?

 

that is not the stop loss at work.. it is the drop protection.. Yes 2 of the trades were closed. The first trade was already closed.

 

My stop-loss does not cover a speedy decent or else it would knock out some of the best trades. My logic works on bars counted.. not the current bar as yet uncounted.

 

I traded that day.. I did not suffer any loss because, there was a market high and a 4hour dojie.. it will not trade when those two conditions are true.

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Just curious.... with OP_BUYSTOP and OP_SELLSTOP trades... do they change modes to OP_BUY and OP_SELL once they are executed and opened by the terminal?

.

 

Pretty sure I know what your asking .. A buystop order (pending order at a price above market) turns into a buy order once the market moves to the price requested.

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

I took another look at the sell side of things and this is what I came up with (aside from, it shouldn't be static)

 

 

//double BuyDenyLevel                  = 1.69;      // This is how it should be set
//double SellDenyLevel                 = 1.59;       // This is how this should be set

  if(type == _OP_BUY)
  {
     if(UseBuy == 0)  return(false);   
     if((_OrderType == OP_BUY) && (OpenRealOrders == 0))  return(false);   
     if((BuyDenyLevel !=0) && (_OrderOpenPrice >= BuyDenyLevel))  return(false);  
                                                                                   
  }       

[center:2rfx703l]_OrderOpenPrice = OrderOpenPrice which will be 1.6 something.

BuyDenyLevel is currently 160 therefore Open Order price will never be higher than buy deny level.

Result: Buy is always allowed[/center:2rfx703l]

 

 

 

if(type == _OP_SELL)
  {
     if(UseSell == 0)  return(false);   
     if((_OrderType == OP_SELL) && (OpenRealOrders == 0))  return(false);      
     if((SellDenyLevel !=0) && (_OrderOpenPrice <= SellDenyLevel))  return(false);  sell deny level
  }                                                                                  

[center:2rfx703l] _OrderOpenPrice = OrderOpenPrice which will be 1.6 something.

SellDeny Level is currently 155 therefore Open Order price will always be lower than

Result : Sell is never allowed[/center:2rfx703l]

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

CurrentFigure = (MathFloor((CurrentPrice / _Point) / 100) * 100) * _Point;

 

I was wondering this as well. I was curious as to why it didn't use MathAbs, and I still need to research WHY we even need it.

 

The "current figure" line calculates a current price "figure" to the closest 100 pips

MathFloor always produces an integer LOWER than the value given. (in other words, it ALWAYS rounds down and not up)

 

By the way, I have now nearly fully commented the Greezly code, so I know exactly what most of it does and how it all works.... although there are a few gaps... like the one above.

 

I'll be attempting to work on the Gepard code soon... and see what needs to be/can be merged from it. It seems as if a lot can, because it uses similar indicator code, maydeferorder code, and checkorder subroutines. It's the logic of its trading I am yet to unearth.

 

I am also yet to code how to generate the Dynamic stoploss from the internal indicators (although now I have a VERY good idea)

 

The spike protection is also fairly interesting.... although something that compares the current price to the high/low of the last bar seems an obvious solutoin.

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

MathFloor always produces an integer LOWER than the value given. (in other words, it ALWAYS rounds down and not up)

 

I meant to click quote and I clicked kudo instead :p

 

Anyway, you can use MathFloor to round up as well. Say that you have a value with 2 digits after the comma and you want to round anything below or equal to 0.5 to the integer below and anything above 0.5 to the integer above - it's very simple: instead of doing MathFloor(value, 0) you do MathFloor(value + 0.49, 0).

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

 

The spike protection is also fairly interesting.... although something that compares the current price to the high/low of the last bar seems an obvious solutoin.

 

This is what I did for the spike protection.. It might be cumbersome but its an idea. I am sure you can write a better one than I can.. given your background with coding.

 

 if( SpikePipsMargin !=0) int timeminutes15 =15;  total = OrdersTotal();
    {  
      for(i = total - 1; i >= 0; i--)
       {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        
        if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
        
        if(((TimeCurrent() - OrderOpenTime())/60) == timeminutes15 ) 
         {                 
            if (iClose( NULL,PERIOD_M15,1) > iOpen(NULL,PERIOD_M15,1)) //Bulls spike
              {
                if ((iHigh(NULL,PERIOD_M15,1)-iClose(NULL, PERIOD_M15,1)) >= ((iClose(NULL,PERIOD_M15,1) - iOpen(NULL,PERIOD_M15,1))*3.5) || ((iHigh(NULL,PERIOD_M15,1)-iClose(NULL, PERIOD_M15,1))> SpikePipsMargin *0.0001))
                 { 
                  if (OrderOpenPrice() > (Ask+Bid/2 - 3*0.0001))
                  {
                  if(PrintComments)  Print("15 minute spike order closed."); 
                    glOrderClose();
                   } 
                 }
              }                                              
           else if (iOpen(NULL,PERIOD_M15,1) > iClose( NULL,PERIOD_M15,1))  //Bears spike
               {
                 if ((iHigh(NULL,PERIOD_M15,1)-iOpen(NULL, PERIOD_M15,1)) >= ((iOpen(NULL,PERIOD_M15,1)- iClose(NULL,PERIOD_M15,1))*3.5)|| ((iHigh(NULL,PERIOD_M15,1)-iOpen(NULL, PERIOD_M15,1))> SpikePipsMargin *0.0001))
                 {
                   if (OrderOpenPrice() > (Ask+Bid/2 - 3*0.0001))
                   {
                   if(PrintComments)  Print("15 minute spike order closed."); 
                    glOrderClose();                 
               }
           }
        }
     }  
  }
}

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Has anyone else found that back-testing on the weekends yields a different result? Possibly, I am just going nuts for the last 3 weekends!

 

dont forget spreads given in the backtest are different on the weekend.

"It is inconceivable that anyone will divulge a truly effective get-rich scheme for the price of a book."

Victor Niederhoffer (1943–), US hedge fund manager and statistician

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

 

dont forget spreads given in the backtest are different on the weekend.

 

I am not too worried about the spread... I am watching it trade and some trades it enters during the week, it does not enter on weekends.

Tried it will other versions.. been tearing out my hair looking for what I changed..

 

I changed nothing... then I thought I must have been mistaken.. took a vid just to make sure it wasn't me.

 

See when you get old.. you always doubt yourself :-??

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Well, Friday's treading session ended after an NFP report.

 

I haven't seen an NFP news trading EA yet... but I'm sure they exist. I guess it would be fairly trivial to create.

 

*You'd need a news reader (FFCal) to find the news time

* You'd need to ensure that all trades were closed.

*Place a buy and sell stop on either side of the range (which would need to be calculated correctly to avoid fakeouts. )

*As soon as one of the stops gets taken, a stop loss is moved immediately behind the stop open, and a trailing stop kicks in.

The trailing stop should only kick in on support and resistance levels the ticker passes through.

*The other stop going in the other direction gets removed.

*Once the initial trade has hit it's trailing stop, another stop pending order opens in the opposite direction for the rebound, and also contains a trailing stop based on support and resistance levels.

 

I'm going to work on writing some code for asgard's dynamic stop based on indicators....

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Well, Friday's treading session ended after an NFP report.

 

I haven't seen an NFP news trading EA yet... but I'm sure they exist. I guess it would be fairly trivial to create.

 

*You'd need a news reader (FFCal) to find the news time

* You'd need to ensure that all trades were closed.

.

 

Hmm.. this is pretty easy or good enough to suit me.. it has tradehour close.. so good chance all trades should be closed.

 

 
if ((MayOpenDeferOrder) && TradeNFP == false)
       {                       
         if ((DayOfWeek()==5) && (Day() <= 7)) MayOpenDeferOrder = false;
        }  

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

*Once the initial trade has hit it's trailing stop, another stop pending order opens in the opposite direction for the rebound, and also contains a trailing stop based on support and resistance levels.

...

 

I'd be really carefull with this one.. your stop might get taken out with a slight retracement and the market might continue to descend.

 

It has done that a lot lately

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

I'd be really carefull with this one.. your stop might get taken out with a slight retracement and the market might continue to descend.

It has done that a lot lately

 

For sure. You'd need to give it a good enough distance of the stops to avoid any fakeouts. This would probably need more study across more NFP reports. The last NFP report on the EU went from mid pivot-support1, crashed through to Support level2, then rebounded all the way up to resistance level 1.... so placing openings closeby support and resistance levels is probably a good idea.

... anyway, it's just an idea.

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Here's some preliminary code I just that puts some dynamic stop closing in.

At the moment it's only based on the result of the Accelerator indicator. (A positive value = sell, a negative value = buy). I'm not sure if it will, or even needs to, include any other indicators at this point.

 

if( UseDynamicStoploss !=0)
{
 total = OrdersTotal(); 
 for(i = total - 1; i >= 0; i--)
 {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       
    if(OrderSymbol() != Symbol())  continue;
       
    if(OrderType()==OP_BUY)
    {
       if(UseAcceleratorIndicator == 1 && miAccelerator > 0) 
       {
          glOrderClose();
          if(PrintComments)  Print("Dynamic indicator stoploss closed order.");
       }
    } 
    else if(OrderType()==OP_SELL)
    {
       if(UseAcceleratorIndicator == 1 && miAccelerator < 0)
       { 
          glOrderClose();     
          if(PrintComments)  Print("Dynamic indicator stoploss closed order.");            
       }
    }
 }
}

Link to comment
Share on other sites

Re: Building your own EA G/08.

 

Here's some preliminary code I just that puts some dynamic stop closing in.

At the moment it's only based on the result of the Accelerator indicator. (A positive value = sell, a negative value = buy). I'm not sure if it will, or even needs to, include any other indicators at this point.

 

if( UseDynamicStoploss !=0)
{
 total = OrdersTotal(); 
 for(i = total - 1; i >= 0; i--)
 {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       
    if(OrderSymbol() != Symbol())  continue;
       
    if(OrderType()==OP_BUY)
    {
       if(UseAcceleratorIndicator == 1 && miAccelerator > 0) 
       {
          glOrderClose();
          if(PrintComments)  Print("Dynamic indicator stoploss closed order.");
       }
    } 
    else if(OrderType()==OP_SELL)
    {
       if(UseAcceleratorIndicator == 1 && miAccelerator < 0)
       { 
          glOrderClose();     
          if(PrintComments)  Print("Dynamic indicator stoploss closed order.");            
       }
    }
 }
}

 

Excellent.. did you try it and see how it goes?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...