help me with this code idea is given below

 
The program should use volume that is greater than average and support and resistance levels to determine buying and selling opportunities.
If the volume is greater than average and the price breaks out either up or down from the support or resistance level, the program should place a trade with a stop loss of 5 points and a take profit of 5 points.
Entry rules for the program include volume being greater than average and the price rejecting off the support or resistance level or breaking out of the support or resistance level.
The program should compare the volume bar to the previous candles to identify strong buying or selling pressure.

The program should look at the price movement to identify strong buying or selling pressure and observe the direction of the wick to identify buying or selling pressure


here is the code with error

double stopLossPrice, takeProfitPrice;


void OnTick()

{

    // Calculate the average volume for the past 20 bars

    double averageVolume = iVolume(NULL, PERIOD_M5, 1) + iVolume(NULL, PERIOD_M5, 2) + iVolume(NULL, PERIOD_M5, 3) + iVolume(NULL, PERIOD_M5, 4) + iVolume(NULL, PERIOD_M5, 5) + iVolume(NULL, PERIOD_M5, 6) + iVolume(NULL, PERIOD_M5, 7) + iVolume(NULL, PERIOD_M5, 8) + iVolume(NULL, PERIOD_M5, 9) + iVolume(NULL, PERIOD_M5, 10) + iVolume(NULL, PERIOD_M5, 11) + iVolume(NULL, PERIOD_M5, 12) + iVolume(NULL, PERIOD_M5, 13) + iVolume(NULL, PERIOD_M5, 14) + iVolume(NULL, PERIOD_M5, 15) + iVolume(NULL, PERIOD_M5, 16) + iVolume(NULL, PERIOD_M5, 17) + iVolume(NULL, PERIOD_M5, 18) + iVolume(NULL, PERIOD_M5, 19) + iVolume(NULL, PERIOD_M5, 20);

    averageVolume = averageVolume / 20;


    // Define the support and resistance levels

    double support = 1.2000;

    double resistance = 1.2500;


    // Get the current market price

    double price = MarketInfo(Symbol(), MODE_BID);


    // Check if the volume is greater than the average volume

    if (iVolume(NULL, PERIOD_M5, 0) > averageVolume)

    {

        // Check if the price is rejecting off the support or resistance level

        if (price > resistance || price < support)

        {

            // Place a trade with a stop loss and take profit of 5 points and slippage of 5 points

            stopLossPrice = price - 0.0005;

            takeProfitPrice = price + 0.0005;

            int ticket = OrderSend(Symbol(), OP_BUY, 0.1, price, 5, stopLossPrice, takeProfitPrice, "My order", 0, 0, Green);


            // Check if the trade was executed successfully

            if (ticket > 0)

            {

                Print("Order executed successfully");

            }

            else

            {

                Print("Order execution failed with error #", GetLastError());

            }

        }

        // Check if the price is breaking out of the support or resistance level

        else if ((price > resistance && MarketInfo(Symbol(), MODE_CLOSE, 1) < resistance) || (price < support && MarketInfo(Symbol(), MODE_CLOSE, 1) > support))

        {

            // Place a trade with a stop loss and take profit of 5 points and slippage of 5 points

            stopLossPrice = price - 0.0005;

            takeProfitPrice = price + 0.0005;

            int ticket = OrderSend(Symbol(), OP_BUY, 0.1, price, 5, stopLossPrice, takeProfitPrice, "My order", 0, 0, Green);


            // Check if the trade was executed successfully

            if (ticket > 0)

            {

                Print("Order executed successfully");

            }

            else

            {

'}' - unexpected end of program jhkjhk.mq4 48 55
'{' - unbalanced parentheses jhkjhk.mq4 4 1

 

Forum on trading, automated trading systems and testing trading strategies

icustom function in expert 0.0 problem

Fernando Carreiro, 2023.02.13 18:29

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post. An also remove all unnecessary white-space from your code.


 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3.             else
    
                { <<<<<<<<<<<< Obviously missing code after here.
    '}' - unexpected end of program jhkjhk.mq4 48 55
    '{' - unbalanced parentheses jhkjhk.mq4 4 1
    

    Do not post code that will not even compile.

  4. sunnybgc: help me with this code idea is given below

    Until you can state your requirements in concrete terms, it can not be coded. How do you determine support and resistance, exactly?

    Help you with what? You haven't stated a problem, you stated a want. 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)

  5. stopLossPrice = price - 0.0005;
    
    takeProfitPrice = price + 0.0005;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)