Expert code help, Take Profit add in MQL5

 

Hi.

I need help on my code. Maybe some can help me :)

I need next:

1. I need to be able to set the Take Profit value in the settings.

2. When the order is opened, the Take Profit set in the settings is set.

3. If the position has been reversed for 1 minute, close the order.

4. If current candle changes direction by 2% compared to the previous one, give a Alert.

Thank you so much.

#include <Trade/Trade.mqh>
int handle;

datetime lastSignal;

CTrade trade;

input string indexCurrentLabel = "Hetkel küündlaid: ";
input string indexLastLabel = "Viimaseid küünlaid: ";
input string lastSignalLabel = "Viimane signaal: ";
input string takeProfitLabel = "Määratud kasum: ";

input int indexCurrentSetting = 1;
input int indexLastSetting = 1;

input bool showIndexCurrent = true;
input bool showIndexLast = true;
input bool showLastSignal = true;

int OnInit()
{
   string name = "Market\\ArrowZigZag.ex5";
   handle = iCustom(_Symbol, PERIOD_CURRENT, name, 12, 5, 3);

   return (INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
}

void OnTick()
{

   int indexCurrent = indexCurrentSetting, indexLast = indexLastSetting;
   for (int i = 0; i < 10000; i++)
   {
      double indiRed[];
      CopyBuffer(handle, 1, i, 1, indiRed);

      double indiGreen[];
      CopyBuffer(handle, 2, i, 1, indiGreen);

      if (indiGreen[0] > 0 || indiRed[0] > 0)
      {
         if (indexCurrent < 0)
         {
            indexCurrent = i;
         }
         else
         {
            indexLast = i;

            datetime time = iTime(_Symbol, PERIOD_CURRENT, i);
            if (time > lastSignal)
            {
               if (indiGreen[0] > 0)
               {
                  Print(__FUNCTION__, " > Uus ostusignaal ", time);
                  trade.PositionClose(_Symbol);
                  trade.Buy(1);
               }
               else if (indiRed[0] > 0)
               {
                  Print(__FUNCTION__, " > Uus müügisignaal ", time);
                  trade.PositionClose(_Symbol);
                  trade.Sell(1);
               }
            }
            lastSignal = time;
            break;
         }
      }
   }

   string commentText = "";
   if (showIndexCurrent)
      commentText += indexCurrentLabel + IntegerToString(indexCurrent) + "\n";
   if (showIndexLast)
      commentText += indexLastLabel + IntegerToString(indexLast) + "\n";
   if (showLastSignal)
      commentText += lastSignalLabel + TimeToString(lastSignal);

   Comment(commentText);
}
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Please don't create topics randomly in any section. It has been moved to the section: Expert Advisors and Automated Trading

Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

 
MarioLaul: I need help on my code. Maybe some can help me :)

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)