help to code

 
383 / 5000

Résultats de traduction

Could someone help me, i cannot code. This code is instructed to: sell when the market is falling and buy when the market is rising, close a position when it has made a profit of 10 euros.

To know if the market is up, it means that the last candle is higher than the 5th, conversely to know if the market is down.

Thank you for your help.

 

I coded this, can someone change it or create some other code so that I can have the instructions requested above.


***
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

 
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property version "1.00"
#include <Trade\Trade.mqh>
CTrade trade ;
void OnTick()
  {
   MqlRates mrate[];
   ArraySetAsSeries(mrate,true);
   if(CopyRates(_Symbol,_Period,0,10,mrate)<0)
      return;
   if(PositionsTotal() < 1)
     {
      if(mrate[1].close>mrate[5].close && mrate[1].close>mrate[1].open)
        {
         double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
         double stoploss = ask - 100 * _Point ;
         double takeprofit = ask + 100 * _Point ;
         if(trade.Buy(0.1, _Symbol, ask, stoploss, takeprofit))
           {
            int code = (int) trade . ResultRetcode();
            ulong ticket = trade . ResultOrder();
            Print(" Code: " + (string) code);
            Print(" Ticket: " + (string) ticket);
           }
        }
      if(mrate[1].close<mrate[5].close && mrate[1].close<mrate[1].open)
        {
         double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
         double sellStoploss = bid + 100 * _Point ;
         double sellTakeprofit = bid - 100 * _Point ;
         if(trade.Sell(0.1, _Symbol, bid, sellStoploss, sellTakeprofit))
           {
            int code = (int) trade . ResultRetcode();
            ulong ticket = trade . ResultOrder();
            Print(" Code: " + (string) code);
            Print(" Ticket: " + (string) ticket);
           }
        }
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

here you go sir

 
  1. Khuman Bakhramirad: here you go sir

    You should have edited your original post not reposted.

  2.          double stoploss = ask - 100 * _Point ;
             double takeprofit = ask + 100 * _Point ;
    ⋮
             double sellStoploss = bid + 100 * _Point ;
             double sellTakeprofit = bid - 100 * _Point ;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at 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 to 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 (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. 39863092: Could someone help me, i cannot code. … Thank you for your help.-

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  4. 39863092: b>39863092: close a position when it has made a profit of 10 euros.

    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 problem.
              No free help 2017.04.21

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

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


 

Thank you very much, you are brilliant !!!


Khuman Bakhramirad :

ici vous allez monsieur