Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL5 (http://www.expert-advisor.com/forum/forumdisplay.php?f=221)
-   -   Hilfe bei Expert Advisor. (http://www.expert-advisor.com/forum/showthread.php?t=7359)

CodeNewbie 03.10.23 21:28

Hilfe bei Expert Advisor.
 
Hallo. Versuche mich an einem EA. Aber leider nimmt er die trade.Sell und trade.buy Funktion leider nicht. Könnte mir dabei jemand behilflich sein wo mein Fehler liegt? Hier der Code.

#include <Trade\Trade.mqh>

CTrade trade;

input int stopLossPips = 150; // Stop Loss in Pips
input int takeProfitPips = 200; // Take Profit in Pips
input int trailStopPips = 10; // Trailing Stop in Pips

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initialize your EA here
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Deinitialize your EA here
}

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBO L_ASK),_Digits);
double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBO L_BID),_Digits);

//--- Fractal variables
double fractalHigh, fractalLow;
string signal="";

fractalHigh = iHigh(Symbol(), 0, iHighest(Symbol(), 0, MODE_HIGH, 5, 1));
fractalLow = iLow(Symbol(), 0, iLowest(Symbol(), 0, MODE_LOW, 5, 1));

if((iHigh(Symbol(), 0, 2) < iHigh(Symbol(), 0, 1) && iHigh(Symbol(), 0, 1) > iHigh(Symbol(), 0, 0)) && (iHigh(Symbol(), 0, 1) > iHigh(Symbol(), 0, 3) && iHigh(Symbol(), 0, 1) > iHigh(Symbol(), 0, 4)))
{
fractalHigh = iHigh(Symbol(), 0, 1);
signal="sell";
}

if((iLow(Symbol(), 0, 2) > iLow(Symbol(), 0, 1) && iLow(Symbol(), 0, 1) < iLow(Symbol(), 0, 0)) && (iLow(Symbol(), 0, 1) < iLow(Symbol(), 0, 3) && iLow(Symbol(), 0, 1) < iLow(Symbol(), 0, 4)))
{
fractalLow = iLow(Symbol(), 0, 1);
signal="buy";
}

//--- Buy condition
if(fractalLow != 0)
{
double stopLoss = fractalLow - stopLossPips * _Point;
double takeProfit = fractalLow + takeProfitPips * _Point;
double trailingStop = fractalLow - trailStopPips * _Point;

// Retrieve the current Ask price
if (signal =="buy" && PositionsTotal()<1)
{
// Place buy order here using Ask
trade.Buy(0.10,NULL,Ask,(Ask-200 * _Point),(Ask+150 * _Point),NULL, stopLoss, takeProfit, trailingStop);
}
}

//--- Sell condition
if(fractalHigh != 0)
{
double stopLoss = fractalHigh + stopLossPips * _Point;
double takeProfit = fractalHigh - takeProfitPips * _Point;
double trailingStop = fractalHigh + trailStopPips * _Point;

// Retrieve the current Bid price
if (signal =="sell" && PositionsTotal()<1)
{
// Place sell order here using Bid
trade.Sell(0.10,NULL,Bid,(Bid+200 * _Point),(Bid-150 * _Point),NULL, stopLoss, takeProfit, trailingStop);
}
}
}

Indikator-Trading 04.10.23 10:18

Hier ist die Funktion, welche du aufrufen willst:

bool Sell(
double volume, // Volumen der Position
const string symbol=NULL, // Symbol
double price=0.0, // Ausführungspreis
double sl=0.0, // Preis von Stop Loss
double tp=0.0, // Preis von Take Profit
const string comment="" // Kommentar
)

d.h. dein Aufruf von

trade.Sell(0.10,NULL,Bid,(Bid+200 * _Point),(Bid-150 * _Point),NULL, stopLoss, takeProfit, trailingStop);

hat zuviele und falsche Parameter:

volume = 0.10;
symbol = NULL;
price = Bid;
sl = (Bid+200 * _Point);
tp = (Bid-150 * _Point);
comment = NULL;
Diese sind so ok, allerdings sind da jetzt noch "stopLoss, takeProfit, trailingStop);" mit dran und damit kann die Funktion nichts anfangen


Alle Zeitangaben in WEZ +2. Es ist jetzt 03:45 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum