Page 1 of 3 123 LastLast
Results 1 to 10 of 23
 2 Attachment(s)    

Thread: Lots Multiplier( help Please)

  1. #1
    joepayne
    Guest

    Post Lots Multiplier( help Please)

    Hi

    Can anybody please help me!

    I want to write code to multiply the Lots every time A trade has stopped at stop loss and to reset the Lots if a trade has stopped at take profit.

    I am new to the programming language and are struggling

    Please help

  2. #2
    Junior Member
    Join Date
    Mar 2009
    Posts
    14

    Default

    if(OrderSelect(0,SELECT_BY_POS,MODE_HISTORY)){
    if(OrderProfit() < 0)My_Lots = OrderLots * My_Lot_Increment;
    else My_Lots = Original_Lots;
    }

  3. #3
    joepayne
    Guest

    Default

    thanks I will give it a try!!!!

    Joe

  4. #4
    joepayne
    Guest

    Default

    Hi Kennyhubbard

    It dose not work if I test the it it only increment it ones and then it stays there and even with a profit it stays on the incremented value and dose not reset.

    thanks for the help

  5. #5
    Junior Member
    Join Date
    Mar 2009
    Posts
    14

    Default

    Hi joe,

    There are a million places where this could go wrong. The code I posted was very simple and broad based. I am assuming that you are keeping it really simple, so you don't plan to trade this with other EA's, etc.....

    There are one or two problems in the above code. The OrderLots should read OrderLots()

    Anyway, if you post the code, I may be able to help you further.

  6. #6
    joepayne
    Guest

    Default

    Here is the code!! If I have lost 1 it must multiply Lots with 2. if I lost 2 it must multiply Lots with 4. If I lost 3 it must multiply Lots with 8......and so on. If I had a win at any stage between it must reset the Lots to 0.1 untill a lost and remultiply it again.

    thanks for the help. I think if it works it is going to be a profitable EA. The gamblers use this system to win on roulette to win on Black or Red. I think if I can combine it with forex it will be profitable. It makes

    thanks
    Joe

    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4



    extern int MagicNumber = 0;
    extern bool SignalMail = False;
    extern bool EachTickMode = True;
    extern double Lots = 0.1;
    extern int Slippage = 3;
    extern bool UseStopLoss = True;
    extern int StopLoss = 10;
    extern bool UseTakeProfit = True;
    extern int TakeProfit = 10;
    extern bool UseTrailingStop = False;
    extern int TrailingStop = 30;

    int BarCount;
    int Current;
    bool TickCheck = False;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init() {
    BarCount = Bars;

    if (EachTickMode) Current = 0; else Current = 1;

    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit() {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start() {
    int Order = SIGNAL_NONE;
    int Total, Ticket;
    double StopLossLevel, TakeProfitLevel;



    if (EachTickMode && Bars != BarCount) TickCheck = False;
    Total = OrdersTotal();
    Order = SIGNAL_NONE;

    //+------------------------------------------------------------------+
    //| Variable Begin |
    //+------------------------------------------------------------------+


    double Buy1_1 = iADX(NULL, 0, 6, PRICE_CLOSE, MODE_MAIN, Current + 0);
    double Buy1_2 = iADX(NULL, 0, 5, PRICE_CLOSE, MODE_MAIN, Current + 0);

    double Sell1_1 = iADX(NULL, 0, 6, PRICE_CLOSE, MODE_MAIN, Current + 0);
    double Sell1_2 = iADX(NULL, 0, 5, PRICE_CLOSE, MODE_MAIN, Current + 0);




    //+------------------------------------------------------------------+
    //| Variable End |
    //+------------------------------------------------------------------+

    //Check position
    bool IsTrade = False;

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Buy) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| Signal End(Exit Buy) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    } else {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Sell) |
    //+------------------------------------------------------------------+



    //+------------------------------------------------------------------+
    //| Signal End(Exit Sell) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Signal Begin(Entry) |
    //+------------------------------------------------------------------+

    if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;

    if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;


    //+------------------------------------------------------------------+
    //| Signal End |
    //+------------------------------------------------------------------+

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    if (!EachTickMode) BarCount = Bars;

    return(0);
    }
    Last edited by joepayne; 05-27-2010 at 10:19.

  7. #7
    Junior Member
    Join Date
    Mar 2009
    Posts
    14

    Default

    The code I showed you earlier has a bug............here is the correct code.........
    PHP Code:
    double Get_Lots()
    {
       if(
    OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)){
          if(
    OrderProfit() < 0)double lLots OrderLots() *  Lot_Increment;
          else 
    lLots Lots;
       }
       else 
    lLots Lots;
       return(
    NormalizeDouble(lLotsLotDigits));

    The system that you are referring to is a martingale system and there is a lot of debate surrounding the use of these systems. I know which side of the fence I sit on this one, but its your money......personally I think you have a better chance at the roulette.
    Attached Files Attached Files
    Last edited by kennyhubbard; 05-27-2010 at 13:28.

  8. #8
    joepayne
    Guest

    Default

    Thanks for the help. I just need to fine tune it. then I hope it works.

    Thanks again
    Joe

  9. #9
    joepayne
    Guest

    Default

    Thanks kennyhubbard

    it works great. now all I need is if it has lost 3 or 4 times it must also reset the Lots to 0.1

    Joe

  10. #10
    Junior Member
    Join Date
    Mar 2009
    Posts
    14

    Default

    PHP Code:
    double Get_Lots() 

       if(
    OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)){ 
          if(
    OrderProfit() < 0)double lLots OrderLots() *  Lot_Increment
          else 
    lLots Lots
       } 
       else 
    lLots Lots
       if(
    lLots Max_Lots)lLots Lots;//<<<<<<<<<<<<<<<<<<<<<<<<<<<
       
    return(NormalizeDouble(lLotsLotDigits)); 
    Just add the extra line to limit the max lots that you desire. You need to define Max_Lots at the beginning of the program, probably an extern variable is best.

Similar Threads

  1. help with multiplier profit EA
    By arbus in forum Ideas for expert advisors
    Replies: 2
    Last Post: 07-28-2011, 16:27
  2. StopLoss & TakeProfit using range/multiplier
    By jidonk in forum MQL programming
    Replies: 0
    Last Post: 01-12-2010, 05:32
  3. Change lots/multiplier to lots=0.01 gives OrderSend error 130?
    By sleepypipsCDN in forum MQL programming
    Replies: 7
    Last Post: 04-12-2009, 09:17
  4. Mini Lots - Micro Lots
    By funyoo in forum Trading discussion
    Replies: 0
    Last Post: 01-23-2009, 12:06

Tags for this Thread

100, adx, ea works, eurusd, ex4, expert, forex, free, how to, magic, main, martingale, profit, profitable, programming, real, signal, signals, simple, slippage, sma, stop, stoploss, system, systems, test, time, trading, trend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •