Need someone to code a simple breakout robot for mt4, I will attach what I have but it has several errors

 

Hi,

This robot logic is based on Tom Hougaards advanced school run strategy which he distributes freely to all through his telegram resource channel. 

We want the robot to enter the market based on a break of a specified range determined by a time frame, specifically we want it to scan the 4th 5 min bar of the Frankfurt open on the dax index to determine the specified breakout range, which is the total of the price movement between 715 and 720 gmt ie the total range of the 4th 5min bar, pretty simple

The robot should go long if break above with stop placed opposite the specified range plus the current spread and go short if break below same but opposite logic, and should never be long and short simultaneously.

The robot should only take one long and one short signal if either are presented in a 24 hr period (today long was good for 106 pts and short was good for 35 pts as we speak)

The robot should have the option for a fixed sl or to set sl at the opposite end of the specific range plus spread

It should have a trailing stop option with start and step specfic inputs

It should have risk % function where it bases lot size for order on the stop distance of the breakout range plus spread.

Would like to see the option for adding more orders to winning trade with options for additional order distance and even maybe an option for % lot size increase for each additional order added 

Would like the fixed tp option as well as trailing option to be able to manage all open orders somehow maybe with basket pips or however we need to approach it

Would like the robot to print the winning % for long and short trades as well as maybe a daily weekly monthly and yearly profit on screen and would like it to show max floating negative too

Thanks for reading

[".txt" text file attachment removed by moderator]

Files:
 

Please attach a proper source code file with a valid MQL file extension.

Please don't create topics randomly in any section. It has been moved to the section: MQL4 e MetaTrader 4

 
  • Usually people who cannot code do not receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free).
  • Finally, you also have the option to hire a programmer in the Freelance section.
 

Please don't post the same topic multiple times. Post only once and in a relevant thread and correct forum section.

Two of your posts on other threads have been removed as duplicates (please read your private messages for more information).

 
Fernando Carreiro #:

Please don't post the same topic multiple times. Post only once and in a relevant thread and correct forum section.

Two of your posts on other threads have been removed as duplicates (please read your private messages for more information).

Sorry but it seems my post disappeared
 
Matt Hipple #: Sorry but it seems my post disappeared

Then how did you manage to post to it?

 
Matt Hipple:

Hi,

This robot logic is based on Tom Hougaards advanced school run strategy which he distributes freely to all through his telegram resource channel. 

We want the robot to enter the market based on a break of a specified range determined by a time frame, specifically we want it to scan the 4th 5 min bar of the Frankfurt open on the dax index to determine the specified breakout range, which is the total of the price movement between 715 and 720 gmt ie the total range of the 4th 5min bar, pretty simple

The robot should go long if break above with stop placed opposite the specified range plus the current spread and go short if break below same but opposite logic, and should never be long and short simultaneously.

The robot should only take one long and one short signal if either are presented in a 24 hr period (today long was good for 106 pts and short was good for 35 pts as we speak)

The robot should have the option for a fixed sl or to set sl at the opposite end of the specific range plus spread

It should have a trailing stop option with start and step specfic inputs

It should have risk % function where it bases lot size for order on the stop distance of the breakout range plus spread.

Would like to see the option for adding more orders to winning trade with options for additional order distance and even maybe an option for % lot size increase for each additional order added 

Would like the fixed tp option as well as trailing option to be able to manage all open orders somehow maybe with basket pips or however we need to approach it

Would like the robot to print the winning % for long and short trades as well as maybe a daily weekly monthly and yearly profit on screen and would like it to show max floating negative too

Thanks for reading

[".txt" text file attachment removed by moderator]

Who is “we” ?? How many are you? Is it you and Tom Hougaards ? 
 
Daniel Cioca #: Who is “we” ?? How many are you? Is it you and Tom Hougaards ? 

Sorry just me and others interested in the logic, someone is working on it but not able to get it to work, I will attach the pdf of the strategy published by Tom

Entry spacing is another important parameter that Tom mentions, distance to wait from breakout threshold essentialy, ie a 10 pt threshold today would have avoided a fakeout, and would have taken a long and a short, long was good for 60 pts and short was good for 140 plus.

The trailing logic is something we can look at optimizing the start and step values, as with our crude first attempt it showed we could move trailing to somewhere bt 8 and 12 pts to start, then next step 50 to 60 pts, to capture small and big moves but avoid getting stopped at sl more often if that makes sense.

 
William Roeder #: Then how did you manage to post to it?

Are you able to code an ea with this logic?

 
Matt Hipple #: Are you able to code an ea with this logic?

How To Ask Questions The Smart Way. (2004)
          Prune pointless queries.

Yes I can.
          How To Ask Questions The Smart Way. (2004)
          Only ask questions with yes/no answers if you want “yes” or “no” as the answer.

Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
          No free help (2017)

 
William Roeder #:

How To Ask Questions The Smart Way. (2004)
          Prune pointless queries.

Yes I can.
          How To Ask Questions The Smart Way. (2004)
          Only ask questions with yes/no answers if you want “yes” or “no” as the answer.

Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
          No free help (2017)

Ohhh the condescent, did you take a few moments to scan the attached strategy in the above zip file? It actually happens to be very interesting, and is written by a real veteran trader who has made several million $ in the markets (Tom Hougaard).... 

Check it out before throwing it in the trash you might just find the information intriguing and decide it could be a viable strategy.

And here is the code mql4programmer.com came up with. I can fix your car basically regardless of the problem, although I will typically pay someone to paint, but I am not a programmer though I have done some java some vb as well as some matlab and some aml in school, but I would think someone would be intrigued if they just read the little zip file attached above...

Good day sirs

/* Input Parameters */
input int EntryHour = 7;       // Hour to scan for trades
input int EntryMinute = 20;    // Minute of hour to scan for trades
input int BarsToScan = 1;      // Number of previous bars to scan
input double RiskPercent = 1;  // Lot size based on % risk
input double MaxLotSize = 10;  // Maximum lot size used for trades
input double LotSize = 0.01;   // Fixed lot size used for trades
input bool UseFixedLotSize = false; // Option to use fixed lot size instead of risk %
input double LotSizePercentIncrease = 10; // % increase for lot size when adding to winning trades
input double DistanceBetweenOrders = 10; // Distance between additional orders in points
input int StopLoss = 50;      // Fixed stop loss in points
input bool UseTrailingStop = true;  // Option to use trailing stop
input int TrailingStart = 20;  // Trailing stop start in points
input int TrailingStep = 20;   // Trailing stop step in points
input int StopBuffer = 2;      // Buffer added to stop loss
input bool ShowMaxFloatingLoss = true; // Option to show max floating loss on screen
input bool ShowProfit = true;  // Option to show profit on screen
input bool ShowWinPercentage = true;  // Option to show win percentage on screen
input bool ShowConsecutiveWins = true; // Option to show consecutive wins on screen
input bool ShowConsecutiveLosses = true;  // Option to show consecutive losses on screen
input int GMTOffset = 0;      // GMT offset for broker time (in hours)


/* Global Variables */
double Lots;
double StopLossPrice;
double TakeProfit;
double LastTradePrice;
double FloatingProfit;
double MaxFloatingLoss;
double RiskAmount;
int NumberOfWinningShortTrades;
int NumberOfWinningLongTrades;
int ConsecutiveWins;
int ConsecutiveLosses;


/* Trading Functions */
void OpenPosition(int type) {
    int ticket;
    if (type == OP_SELL) {
        ticket = Sell(Lots);
        LastTradePrice = Bid;
        NumberOfWinningShortTrades++;
    } else if (type == OP_BUY) {
        ticket = Buy(Lots);
        LastTradePrice = Ask;
        NumberOfWinningLongTrades++;
    }

    if (ticket > 0) {
        if (UseTrailingStop) {
            if (type == OP_SELL) {
                // Set initial trailing stop for sell trade
                SetTrailingStop(ticket, LastTradePrice - TrailingStart * _Point, TrailingStep * _Point);
            } else if (type == OP_BUY) {
                // Set initial trailing stop for buy trade
                SetTrailingStop(ticket, LastTradePrice + TrailingStart * _Point, TrailingStep * _Point);
            }
        }

        // Set stop loss and take profit levels for the trade
        SetStopLoss(ticket, StopLossPrice);
        SetTakeProfit(ticket, TakeProfit);
    }
}

void ClosePosition(int ticket) {
    // Close the trade
    if (ticket > 0) {
        CloseTrade(ticket);
    }

    // Reset trade variables
    LastTradePrice = 0;
    FloatingProfit = 0;
    StopLossPrice = 0;
    TakeProfit = 0;

    // Update consecutive wins/losses counter
    if (ticket > 0) {
        ConsecutiveWins++;
        ConsecutiveLosses = 0;
    } else {
        ConsecutiveLosses++;
        ConsecutiveWins = 0;
    }
}


/* Event Functions */
void OnTick() {
    int hour = TimeHour(TimeCurrent()) - GMTOffset;
    int minute = TimeMinute(TimeCurrent());
    int allowedHour = EntryHour - GMTOffset;
    int allowedMinute = EntryMinute;

    // Only scan for trades at specified time
    if (hour != allowedHour || minute != allowedMinute) {
        return;
    }

    // Calculate the breakout price range
    int barsBack = BarsToScan + 1;
    double rangeLow = Low[barsBack];
    double rangeHigh = High[barsBack];
    for (int i = barsBack; i > 0; i--) {
        if (Low[i] < rangeLow) {
            rangeLow = Low[i];
        }
        if (High[i] > rangeHigh) {
            rangeHigh = High[i];
        }
    }

    // Check for sell signal
    if (Bid < rangeLow) {
        // Calculate lot size
        if (UseFixedLotSize) {
            Lots = LotSize;
        } else {
            RiskAmount = AccountBalance() * RiskPercent / 100;
            Lots = RiskAmount / StopLossPrice / 10000;
            if (Lots > MaxLotSize) {
                Lots = MaxLotSize;
            }
        }

        // Calculate stop loss and take profit
        StopLossPrice = rangeHigh + StopBuffer * _Point;
        TakeProfit = Bid - (StopLossPrice - Bid) * 2;

        // Open sell position
        if (OrderType() == -1) {
            // Close existing sell trade if present
            int ticket = OrderTicket();
            if (ticket > 0) {
                ClosePosition(ticket);
            }
        } else {
            OpenPosition(OP_SELL);
        }
    }

    // Check for buy signal
    if (Ask > rangeHigh) {
        // Calculate lot size
        if (UseFixedLotSize) {
            Lots = LotSize;
        } else {
            RiskAmount = AccountBalance() * RiskPercent / 100;
            Lots = RiskAmount / (Ask - StopLossPrice) / 10000;
            if (Lots > MaxLotSize) {
                Lots = MaxLotSize;
            }
        }

        // Calculate stop loss and take profit
        StopLossPrice = rangeLow - StopBuffer * _Point;
        TakeProfit = Ask + (Ask - StopLossPrice) * 2;

        // Open buy position
        if (OrderType() == -1) {
            OpenPosition(OP_BUY);
        } else {
            // Close existing buy trade if present
            int ticket = OrderTicket();
            if (ticket > 0) {
                ClosePosition(ticket);
            }
        }
    }
}

void OnTrade() {
    int ticket;
    double openPrice;
    double closePrice;
    double lotSize;
    int type;

    // Loop through all trades and update floating profit
    for (int i = 0; i < OrdersTotal(); i++) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            ticket = OrderTicket();
            openPrice = OrderOpenPrice();
            lotSize = OrderLots();
            type = OrderType();

            if (type == OP_SELL) {
                if (UseTrailingStop) {
                    // Update trailing stop for sell trade
                    SetTrailingStop(ticket, openPrice - TrailingStart * _Point, TrailingStep * _Point);
                }
                if (Bid < openPrice) {
                    // Close sell trade due to opposite signal
                    ClosePosition(ticket);
                } else {
                    // Update stop loss and take profit for sell trade based on average open price
                    FloatingProfit += (openPrice - Bid) * lotSize;
                    StopLossPrice = openPrice + (FloatingProfit / OrdersTotal() - StopBuffer * _Point);
                    SetStopLoss(ticket, StopLossPrice);
                    SetTakeProfit(ticket, LastTradePrice - (StopLossPrice - LastTradePrice) * 2);
                }
            } else if (type == OP_BUY) {
                if (UseTrailingStop) {
                    // Update trailing stop for buy trade
                    SetTrailingStop(ticket, openPrice + TrailingStart * _Point, TrailingStep * _Point);
                }
                if (Ask > openPrice) {
                    // Close buy trade due to opposite signal
                    ClosePosition(ticket);
                } else {
                    // Update stop loss and take profit for buy trade based on average open price
                    FloatingProfit += (Ask - openPrice) * lotSize;
                    StopLossPrice = openPrice - (FloatingProfit / OrdersTotal() + StopBuffer * _Point);
                    SetStopLoss(ticket, StopLossPrice);
                    SetTakeProfit(ticket, LastTradePrice + (LastTradePrice - StopLossPrice) * 2);
                }
            }
        }
    }

    // Add to winning trades if distance between orders is reached
    if (FloatingProfit >= DistanceBetweenOrders * OrdersTotal() * _Point) {

        if (OrderType() == OP_SELL) {
            // Add sell order below current market price
            int ticket = Sell(Lots * (1 + LotSizePercentIncrease / 100.0), 0, Ask - DistanceBetweenOrders * _Point, 0, 0, 0);
            LastTradePrice = OrderOpenPrice();
            FloatingProfit = 0;
        } else if (OrderType() == OP_BUY) {
            // Add buy order above current market price
            int ticket = Buy(Lots * (1 + LotSizePercentIncrease / 100.0), 0, Bid + DistanceBetweenOrders * _Point, 0, 0, 0);
            LastTradePrice = OrderOpenPrice();
            FloatingProfit = 0;
        }
    }

    // Update max floating loss
    double floatingLoss = AccountBalance() - (FloatingProfit + Profit());
    if (floatingLoss < MaxFloatingLoss) {
        MaxFloatingLoss = floatingLoss;
    }
}

void OnInit() {
    // Set variables initial values
    LastTradePrice = 0;
    FloatingProfit = 0;
    MaxFloatingLoss = 0;
    NumberOfWinningShortTrades = 0;
    NumberOfWinningLongTrades = 0;
    ConsecutiveWins = 0;
    ConsecutiveLosses = 0;

    // Calculate stop loss price buffer as points
    StopBuffer = StopLoss / _Point;
}

void OnDeinit(const int reason) {
    // Print statistics on screen when EA is closed
    if (reason == REASON_REMOVE || reason == REASON_CHARTCHANGE || reason == REASON_ACCOUNT) {
        if (ShowProfit) {
            Print("Profit: ", NormalizeDouble(Profit(), 2));
        }
        if (ShowMaxFloatingLoss) {
            Print("Max Floating Loss: ", NormalizeDouble(MaxFloatingLoss, 2));
        }
        if (ShowWinPercentage) {
            Print("Winning Short Trades: ", NumberOfWinningShortTrades, "%\n");
            Print("Winning Long Trades: ", NumberOfWinningLongTrades, "%\n");
        }
        if (ShowConsecutiveWins) {
            Print("Consecutive Wins: ", ConsecutiveWins);
        }
        if (ShowConsecutiveLosses) {
            Print("Consecutive Losses: ", ConsecutiveLosses);
        }
    }
}
Reason: