My shell EA code

Post Reply
censura10
Posts: 5
Joined: Wed Apr 08, 2015 11:36 am

My shell EA code

Post by censura10 »

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
matrixebiz
Trader
Posts: 70
Joined: Wed Nov 16, 2011 4:39 am

My shell EA code

Post by matrixebiz »

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; 
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
matrixebiz
Trader
Posts: 70
Joined: Wed Nov 16, 2011 4:39 am

My shell EA code

Post by matrixebiz »

Great, thanks man
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Post by SteveHopwood »

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.
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
matrixebiz
Trader
Posts: 70
Joined: Wed Nov 16, 2011 4:39 am

My shell EA code

Post by matrixebiz »

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?
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Post by SteveHopwood »

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?
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
matrixebiz
Trader
Posts: 70
Joined: Wed Nov 16, 2011 4:39 am

My shell EA code

Post by matrixebiz »

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.
censura
Trader
Posts: 32
Joined: Wed Jun 06, 2012 12:52 pm

My shell EA code

Post by censura »

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
AnotherBrian

My shell EA code

Post by AnotherBrian »

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.
Post Reply

Return to “Coders Hangout”