Einzelnen Beitrag anzeigen
  #10 (permalink)  
Alt 04.05.23
Lennox Lennox ist offline
Neues Mitglied
 
Registriert seit: Apr 2023
Beiträge: 5
Lennox befindet sich auf einem aufstrebenden Ast
Standard Antwort

Es gibt nun insgesamt 37 geöffnete und 37 geschlossene Klammern jetzt müsste es doch passen richtig?

//+------------------------------------------------------------------+
//| MyStrategy.mq4 |
//| Copyright 2023, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window

//--- input parameters
input color Color=clrYellow;
input bool Input1=false;
input short Input2=800;
input ushort Input3=800;
input string Input4="(1/0)";

// Declare input parameters
extern double LotSize = 1.0;
extern int MovingAveragePeriod = 20;
extern double StopLossPips = 20.0;
extern double TakeProfitPips = 40.0;

// Declare global variables
double MovingAverageBuffer[];
double LastTradePrice;
int LastTradeDirection;
int LastTradeBar;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping

// Resize the moving average buffer
ArrayResize(MovingAverageBuffer, Bars - MovingAveragePeriod + 1);

// Calculate the moving average
for (int i = 0; i < Bars - MovingAveragePeriod + 1; i++)
{
double sum = 0.0;
for (int j = i; j < i + MovingAveragePeriod; j++)
{
sum += Close[j];
}
MovingAverageBuffer[i] = sum / MovingAveragePeriod;
}

return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---

//--- return value of prev_calculated for next call
return(rates_total);
}

//+------------------------------------------------------------------+
//| Handle the tick event |
//+------------------------------------------------------------------+
void OnTick()
{
// Get the current price
double currentPrice = Bid;

// Check if the last trade was a buy
if (LastTradeDirection == 1)
{
// Check if the price has crossed below the moving average
if (currentPrice < MovingAverageBuffer[LastTradeBar])
{
// Place a sell order at the current price
double stopLoss = currentPrice + StopLossPips * Point;
double takeProfit = currentPrice - TakeProfitPips * Point;
OrderSend(Symbol(), OP_SELL, LotSize, currentPrice, 0, stopLoss,
takeProfit, "Sell order", 0, 0, Red);
LastTradeDirection = -1;
LastTradePrice = currentPrice;
LastTradeBar = Bars - 1;
}
}
// Check if the last trade was a sell
else if (LastTradeDirection == -1)
{
// Check if the price has crossed above the moving average
if (currentPrice > MovingAverageBuffer[LastTradeBar])
{
// Place a buy order at the current price
double stopLoss = currentPrice