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

My shell EA code
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79
Page 16 of 23
Author:  censura10 [ Fri Apr 17, 2015 3:19 pm ]
Post subject:  My shell EA code

Hi Steve and others, its been a long time but I am back trading again.

I wonder if someone can help

I am trying to add a step function to the lotsize variable in the basic bones ea

the idea being on each losing trade the step multiplier increase by 1 and on a winning trade it reverts back to 1.


so simply on 3 losses the step multiplier would be 0.3 (starting at 0.1) if the 4th trade is a winner then we are back to step = 1 ie back to 0.1 lotsize.


so in the bones ea i added

Code: Select all

int step=1;

for (int cc = 0; cc <= OrdersHistoryTotal(); cc++)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      
      OverallProfit+= (OrderProfit() + OrderSwap() + OrderCommission() );
      if (OrderProfit() > 0) WinTrades++;
      if (OrderProfit() < 0) LossTrades++;
      if (OrderProfit() > 0) step=1;
      if (OrderProfit() < 0) step++;
      
      GlobalVariableSet("step"+Symbol(),step);
      
   }//for (int cc = 0; cc <= tot -1; cc++)

step=GlobalVariableGet("step"+Symbol());
//lotsize=lotsize*step;
bool SendSingleTrade(string symbol,int type,string comment, double lotsize,double price,double stop,double take)
{
//..........etc
but this did not work

any help gratefully recieved
thank you
Author:  matrixebiz [ Fri May 01, 2015 12:58 pm ]
Post subject:  My shell EA code

Hey Steve,
I'm looking to stop the errors that get generated when the EA tries moving the SL to close to current price.
"Alert: JumpingStopLoss stop loss modification failed with error 130: invalid stops"

I think this is the correct code below but where in your EA would I put it :) ? Thx

Comment: Print(MarketInfo(Symbol(), MODE_STOPLEVEL));

Code: Select all

int StopLevel;

StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);

if (StopLoss < StopLevel) StopLoss = StopLevel;
if (TakeProfit < StopLevel) TakeProfit = StopLevel; 
Author:  SteveHopwood [ Fri May 01, 2015 4:34 pm ]
Post subject:  My shell EA code

matrixebiz » Fri May 01, 2015 12:58 pm wrote:Hey Steve,
I'm looking to stop the errors that get generated when the EA tries moving the SL to close to current price.
"Alert: JumpingStopLoss stop loss modification failed with error 130: invalid stops"

I think this is the correct code below but where in your EA would I put it :) ? Thx

Comment: Print(MarketInfo(Symbol(), MODE_STOPLEVEL));

Code: Select all

int StopLevel;

StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);

if (StopLoss < StopLevel) StopLoss = StopLevel;
if (TakeProfit < StopLevel) TakeProfit = StopLevel; 
In these two functions:

Code: Select all

double CalculateStopLoss(int type, double price)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double stop;

   RefreshRates();
   
   double StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
   double spread = (Ask - Bid) * factor;

   
   if (type == OP_BUY)
   {
      if (!CloseEnough(StopLoss, 0) ) 
      {
         stop = price - (StopLoss / factor);
         if (StopLoss < StopLevel) StopLoss = StopLevel;
         HiddenStopLoss = stop;
      }//if (!CloseEnough(StopLoss, 0) ) 

      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop - (HiddenPips / factor), Digits);
   }//if (type == OP_BUY)
   
   if (type == OP_SELL)
   {
      if (!CloseEnough(StopLoss, 0) ) 
      {
         stop = price + (StopLoss / factor);
         if (StopLoss < StopLevel) StopLoss = StopLevel;
         HiddenStopLoss = stop;         
      }//if (!CloseEnough(StopLoss, 0) ) 
      
      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop + (HiddenPips / factor), Digits);

   }//if (type == OP_SELL)
   
   return(stop);
   
}//End double CalculateStopLoss(int type)

double CalculateTakeProfit(int type, double price)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double take;

   RefreshRates();
   
   double StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
   double spread = (Ask - Bid) * factor;

   
   if (type == OP_BUY)
   {
      if (!CloseEnough(TakeProfit, 0) )
      {
         take = price + (TakeProfit / factor);
         if (TakeProfit < StopLevel) TakeProfit = StopLevel;
         HiddenTakeProfit = take;
      }//if (!CloseEnough(TakeProfit, 0) )

               
      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips / factor), Digits);

   }//if (type == OP_BUY)
   
   if (type == OP_SELL)
   {
      if (!CloseEnough(TakeProfit, 0) )
      {
         take = price - (TakeProfit / factor);
         if (TakeProfit < StopLevel) TakeProfit = StopLevel;
         HiddenTakeProfit = take;         
      }//if (!CloseEnough(TakeProfit, 0) )
      
      
      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips / factor), Digits);

   }//if (type == OP_SELL)
   
   return(take);
   
}//End double CalculateTakeProfit(int type)
Simply copy them over the top of the existing functions. Note that StopLevel needs to be a double rather than an int.

:xm:
Author:  matrixebiz [ Fri May 01, 2015 4:36 pm ]
Post subject:  My shell EA code

Great, thanks man
Author:  SteveHopwood [ Fri May 01, 2015 4:41 pm ]
Post subject:  My shell EA code

Adding that code is one of those tiny jobs I have been meaning to do for ages, so there are new versions of Bob Stuff, Bare Bones and Bugger All Included in post 1.
Author:  matrixebiz [ Fri May 01, 2015 11:05 pm ]
Post subject:  My shell EA code

Looks like I also need to add one of your pip multipliers because I'm adding;

Code: Select all

SM("MinStopLevel: "+MarketInfo(Symbol(), MODE_STOPLEVEL)+NL)
to your comment section and when I check the pair it says 40 but I know the trade closed at SL 4 pips profit so the EA wouldn't have been able to more SL to +4 pips if MinSL is 40 :)
I tried adding *factor at the end but that didn't work 400000 :) What am I doing wrong?
Author:  SteveHopwood [ Fri May 01, 2015 11:16 pm ]
Post subject:  My shell EA code

matrixebiz » Fri May 01, 2015 11:05 pm wrote:Looks like I also need to add one of your pip multipliers because I'm adding;

Code: Select all

SM("MinStopLevel: "+MarketInfo(Symbol(), MODE_STOPLEVEL)+NL)
to your comment section and when I check the pair it says 40 but I know the trade closed at SL 4 pips profit so the EA wouldn't have been able to more SL to +4 pips if MinSL is 40 :)
I tried adding *factor at the end but that didn't work 400000 :) What am I doing wrong?
I know you from old and you are seriously irritating. Every time I feed you a bit of information that could be gleaned by a reasonably intelligent 5 year old, you claim helplessness and demand more.

Stop now and work this stuff out for yourself like the rest of us had to, or I will remove from you the ability to post here at all.

Capiche?
Author:  matrixebiz [ Sun May 03, 2015 12:19 am ]
Post subject:  My shell EA code

Ok, got it. I just didn't want to put somthing in the wrong place and mess it up so I figured I'd ask the writer who would know what to add where in the correct locations in seconds but no worries. I'll figure it out. Thx anyway

EDIT: if there are any 5 year olds out there that want the fix to the above code for it to work properly can PM me, please do not use the above code if you use/need tight SL or TP values.
Author:  censura [ Thu Jul 09, 2015 10:25 am ]
Post subject:  My shell EA code

Hi just a question about trading time code .

Does the code use the broker platform time or the computer time to open and close trading

also I have this as inputs is this correctly typed

+10.55,-18.55,+19.55,-23.00,+02.55,-09.55


thank you
Author:  AnotherBrian [ Thu Jul 09, 2015 1:59 pm ]
Post subject:  My shell EA code

censura » Thu Jul 09, 2015 5:25 am wrote:Hi just a question about trading time code .

Does the code use the broker platform time or the computer time to open and close trading

also I have this as inputs is this correctly typed

+10.55,-18.55,+19.55,-23.00,+02.55,-09.55


thank you
Did you read the Manual two times before asking?
It's on the first post of this thread.
All times are UTC Page 16 of 23