increase lot after get stoplose..

 

hello everyone...

i want the ea open next position using more lot that previous position when first position get stoplose..

example:

if first buy position using 0.1 lot and get stoplose, then next position meet condition, so open position (buy or sell) using more lot like 0.3 lot..

is it difficult?

can ea doing like that?

thx..

 

Sounds a bit Martingale to me, which to me is a BAD IDEA. It's a bit tricky, but an EA could do it.

The pseudo-code I would adopt would be (no, I won't code it all for you)

// this code is uncompiled, untested, and not necessarily correct
int start()
{
...
static datetime LastClosedTrade = 0;
static bool NeedToBoostNextTrade = false;
...
ScanClosedTradesAndSelectMostRecentToClose();
datetime  MostRecentClosedTrade = OrderCloseTime();
if(MostRecentClosedTrade > LastClosedTrade)
{
   if(SelectedTradeClosedAtALoss())
   {
      NeedToBoostNextTrade=true;
   }
   LastClosedTrade=MostRecentClosedTrade;
} 
...
ConsiderGeneratingNewOrder()
...
}
void GenerateANewOrder()
{
...
   double orderLots = SomeNumber;
   if(NeedToBoostNextTrade)
   {
      orderLots=orderLots * 3;
      NeedToBoostNextTrade=false;
   }
...
}
 

thx brewmanz..

ya, the martiangle is dangerous and using full margin to win a little.. i don't like it too..

but i want using the method increament lot after get sl, maybe is good idea.. for signal that have percentance winner/lose = 50:50, is good using increament lot.. maybe enough need max 4 times increament ..

so i want to test it..

this is my code:


extern double TakeProfit = 50;
extern double StopLose = 50;
extern double Lots = 0.1;

extern double range=20;
double dBuyEntry;
double Pip;
extern int Magic = 100; //use this magic for your main position, use Magic + 1 for 1-st buy-stop, use Magic + 2 for last sell-stop
static datetime LastClosedTrade = 0;
static bool NeedToBoostNextTrade = false;

int m_100_order_ticket = 0;
int m_101_order_ticket = 0;
int m_101_order_type   = -1;
double m_101_order_op  = 0;
double m_102_order_op = 0;
int m_102_order_ticket = 0;
double m_100_order_op  = 0;
int m_103_order_ticket=0;

int init(){
Pip = Point;
if(Digits==3||Digits==5)Pip*=10;
TakeProfit *= Pip;
StopLose *= Pip;
          }

int start()
{ 
int ticket, range =20;
int i;
int total = OrdersTotal() - 1;
for ( i = total; i >= 0; i -- )
   {
   if ( !OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) { Print( "OrderSelect error #", GetLastError() ); continue; }
   if ( OrderSymbol() != Symbol() ) { continue; }
   if ( OrderMagicNumber() == Magic ) {  m_100_order_ticket = OrderTicket(); continue; }
   if ( OrderMagicNumber() == Magic + 1 )
      {
      m_101_order_ticket = OrderTicket();
      m_101_order_type = OrderType();
      m_101_order_op = OrderOpenPrice();
      continue;
      }
   if ( OrderMagicNumber() == Magic + 2 ) { m_102_order_ticket = OrderTicket(); m_102_order_op = OrderOpenPrice(); continue; }

   }




 if(New_Bar()){
if (OrdersTotal()<1){
   if ( m_101_order_ticket < 1)//if second doesn't exist - open it!
                         {
     if (High[1]>High[0])

{ticket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,4),3,NormalizeDouble(Ask-StopLose,Digits),NormalizeDouble(Ask+TakeProfit,Digits),0,Green) ;}
   GenerateANewOrder()
                         }



//ScanClosedTradesAndSelectMostRecentToClose();
datetime  MostRecentClosedTrade = OrderCloseTime();
if(MostRecentClosedTrade > LastClosedTrade)
              {
   if(SelectedTradeClosedAtALoss())
                   {
      NeedToBoostNextTrade=true;
                   }
   LastClosedTrade=MostRecentClosedTrade;
              } 

//ConsiderGeneratingNewOrder()



                    }
                  }
return(0);

 }

bool New_Bar()
{
static datetime New_Time=0;
if(New_Time!=Time[0]){
New_Time=Time[0];
return(true);
}
return(false);
}



void GenerateANewOrder()
   {

   double orderLots =  SomeNumber;
   if(NeedToBoostNextTrade)
      {
      orderLots=orderLots * 3;
      NeedToBoostNextTrade=false;
      }
 
return (0);
}

your code have not complete..

please help...

thx..

 
help..
 
extern double TakeProfit = 50;
extern double StopLoss = 50;
extern double Lots = 0.1;
int OT;
double OL;
string _symbol;
int Magic = 12345;
double Pip;

int init()
   {
   Pip = Point;
   //----
   if(Digits==3||Digits==5)
      {
      Pip*=10;
      TakeProfit *= Pip;
      StopLoss *= Pip;
      }
   }

int start()
  {
//----
CheckIfOrderEarned();
//-----
if (what ever condition u want)   
   {
   int ticket=OrderSend(_symbol,OT,Lots,Ask,3,0,0,"",Magic,0,Green);
   
   if (ticket > -1)
      {
      OrderSelect(ticket, SELECT_BY_TICKET);
      bool retrn = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - StopLoss, Ask + TakeProfit , 0, Red);
      if (retrn == false)
      Print("OrderModify() error - ", GetLastError());
      }
   else
      {
      Print("OrderSend() error - ", GetLastError());
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
void CheckIfOrderEarned()
   {
   int i=OrdersHistoryTotal()-1;
   //----
   OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      {                                     
      OT = OrderType();
      OL = OrderLots();
      _symbol = OrderSymbol();
      double OP = OrderProfit();
      if (OrderMagicNumber() == Magic)
         {
         if (OrderProfit() < 0)
            {
            Lots = NormalizeDouble(Lots*2, 2); 
            }
         else
            {
            Lots = 0.1;
            }
         }
      }
   }
something like this
 

hi gjol..

it's error

2010.11.15 17:40:11 2010.10.11 10:06 addlot EURUSD,H1: OrderSend() error - 4106

2010.11.15 17:40:11 2010.10.11 10:06 addlot EURUSD,H1: unknown symbol name for OrderSend function


so i change the code :

 int ticket=OrderSend(_symbol,OT,Lots,Ask,3,0,0,"",Magic,0,Green);

to:

int ticket=OrderSend(Symbol(),OT,Lots,NormalizeDouble(Ask,4),3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",Magic,Green) ;

so can open some position, but error:

2010.11.15 17:45:11 2010.11.12 23:00 addlot EURUSD,H1: OrderSend error 4051
2010.11.15 17:45:11 2010.11.12 23:00 addlot EURUSD,H1: invalid lots amount for OrderSend function


the problem is Lots, so i change the Lots to OL, can not open position..

so what the code for changing the Lots?

thx..

 
hardyyanto:

hi gjol..

it's error

2010.11.15 17:40:11 2010.10.11 10:06 addlot EURUSD,H1: OrderSend() error - 4106

2010.11.15 17:40:11 2010.10.11 10:06 addlot EURUSD,H1: unknown symbol name for OrderSend function

so i change the code :

to:

so can open some position, but error:

2010.11.15 17:45:11 2010.11.12 23:00 addlot EURUSD,H1: OrderSend error 4051
2010.11.15 17:45:11 2010.11.12 23:00 addlot EURUSD,H1: invalid lots amount for OrderSend function

the problem is Lots, so i change the Lots to OL, can not open position..

so what the code for changing the Lots?

thx..


i'm so sorry but i didn't check the code (& of course didn't debug it), i only wrote the this code to give you the idea how to do this
 

I checked it now and the only change needs to be done is:

Lots = NormalizeDouble(OL*2, 2); 

Instead of:

Lots = NormalizeDouble(Lots*2, 2); 
& working perfect
 

thx very much gjol...

it can work perfect...

great..


o ya, how about limit it?

i want the increament only to 3 times..

so i add the code like this:

void CheckIfOrderEarned()
   {
   int i=OrdersHistoryTotal()-1;
   //----
   OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      {                                     
      OT = OrderType();
      OL = OrderLots();
      _symbol = OrderSymbol();
      double OP = OrderProfit();
      
      if (OrderMagicNumber() == Magic)
         {
         for (i=1; i<4; i++){
         if (OrderProfit() < 0)
            {
            
            Lots = NormalizeDouble(OL*2, 2); 
                                
            }
         else
            {
            Lots = 0.1;
            }
                           }
         }
      }
   }

but still increment lot until profit...

it should increment until 3 times, but unlimited untill profit..

what is the wrong...



and this code :

if (ticket > -1)
      {
      OrderSelect(ticket, SELECT_BY_TICKET);
      bool retrn = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - StopLoss, Ask + TakeProfit , 0, Red);
      if (retrn == false)
      Print("OrderModify() error - ", GetLastError());
      }
   else
      {
      Print("OrderSend() error - ", GetLastError());
      }


what is this code for? it that for changing the stop lose and takeprofit value when first tp and sl=0 ?

i am testing not include it to ea, can increment lots too..

and why do u using OT?

OT only open buy position, so i still using Op_BUY or Op_SELL..

thx..

 
hardyyanto:

thx very much gjol...

it can work perfect...

great..

o ya, how about limit it?

i want the increament only to 3 times..

so i add the code like this:

but still increment lot until profit...

it should increment until 3 times, but unlimited untill profit..

what is the wrong...

Lots = 0.1;
if (OrderProfit() < 0 &&  OL < NormalizeDouble(Lots*3,2))

hardyyanto:

and this code :

what is this code for? it that for changing the stop lose and takeprofit value when first tp and sl=0 ?

that's right

hardyyanto:

and why do u using OT?

OT only open buy position, so i still using Op_BUY or Op_SELL..

I took it, from a ready function that i have (some times it comes to use)

 

gjol..

it can not limit the 3 level increment lot.. it still unlimited increment untill profit..

so i change to like this:

if (OrderProfit() < 0 &&  OrderLots() < 0.4)

but it's not good because only limit based of lot when increment until 0.4 from 0.1-->0.2-->0.4, then can not increment again if have get sl..

i want it based of 3 level increment only..

Reason: