Cascade trading combined with Reverse MA
- Asesores Expertos
- Chia Leilypour
- Versión: 1.0
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property enlace "https://www.mql5.com"
#property version "1.00"
#include <Clases_más_comunes.mqh>
// Definir parámetros para las medias móviles
input int fastMAPeriod = 10; // Periodo MA rápido (ej. 10 para scalping)
input int slowMAPeriod = 20; // Periodo MA lento (ej. 20 para scalping)
input ENUM_MA_METHOD maMethod = MODE_SMA;
double lotSize;
int maShift_current = 0;
int maShift_Previous = 1;
bool dinero_suficiente
bool valor_suficiente;
string mensaje;
bool IsBuy;
bool TradeIsOk;
double StopLoss
doble TakeProfit;
input double PorcentajeDeRiesgo=0,01;
input double R2R=2;
input double StopLossPoints=100;
input double MinimumStopLossPoints=25;
ST_StopLoss_TakeProfit arr;
int OnInit()
{
// Inicialización
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Función experta de desinicialización |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Código de limpieza
}
//+------------------------------------------------------------------+
//| Función tick experta |
//+------------------------------------------------------------------+
void OnTick()
{
// Sin desplazamiento para medias móviles
// Usar Media Móvil Simple (SMA)
ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE; // Aplicar a precios de Cierre
// Obtener los valores de las medias móviles actual y anterior
// if (AccountInfoDouble(ACCOUNT_PROFIT)>100){close_All_Orders();}
double fastMA_Current = MACalculator(_Symbol,PERIOD_CURRENT,fastMAPeriod,maShift_current,maMethod,appliedPrice); // MA rápida actual
double slowMA_Current = MACalculator(_Symbol,PERIOD_CURRENT,slowMAPeriod,maShift_current,maMethod,appliedPrice); // MA Lenta Actual
double fastMA_Previous = MACalculator(_Symbol,PERIOD_CURRENT,fastMAPeriod,maShift_Previous,maMethod,appliedPrice); // MA Rápida Anterior
double slowMA_Previous = MACalculator(_Symbol,PERIOD_CURRENT,slowMAPeriod,maShift_Previous,maMethod,appliedPrice); // MA Lenta Anterior
double Refference_MA = MACalculator(_Symbol,PERIOD_CURRENT,100,maShift_Previous,maMethod,appliedPrice);
// Obtener información de la cuenta actual
// Establecer el tamaño del lote para las operaciones
double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); // Precio Ask actual
double bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); // Precio de oferta actual
if(IsNewCanddle(PERIOD_H1))
{
TradeIsOk=true;
//if(PositionsTotal() != 0)canddleCount=canddleCount+1;
}
if(fastMA_Previous < slowMA_Previous && fastMA_Current > slowMA_Current && SymbolOpenOrders(Symbol())==0 && bid< Refference_MA)
{
//lotSize=OptimumLotSize(_Symbol,ask,StopLoss,RiskPercent);
lotSize=0.01;
dinero_suficiente =CheckMoneyForTrade(Symbol(),lotSize,ORDER_TYPE_SELL);
enough_valume=CheckVolumeValue(lotSize,mensaje);
StopLoss=bid+StopLossPoints*Punto();
TakeProfit=bid-R2R*StopLossPoints*Point();
if(enough_money && enough_valume) Trading.Sell(lotSize, NULL, bid, StopLoss,0, "Logic Order");
IsBuy=false;
}
if(fastMA_Previous > slowMA_Previous && fastMA_Current < slowMA_Current && SymbolOpenOrders(Symbol())==0 && ask > Refference_MA)
{
//lotSize=OptimumLotSize(_Símbolo,ask,StopLoss,PorcentajeRiesgo);
lotSize=0.01;
dinero_suficiente =CheckMoneyForTrade(Symbol(),lotSize,ORDER_TYPE_BUY);
enough_valume=CheckVolumeValue(lotSize,mensaje);
StopLoss=bid-PuntosStopLoss*Punto();
TakeProfit=bid+R2R*StopLossPoints*Point();
if(enough_money && enough_valume)Trading.Buy(lotSize, NULL, ask, StopLoss,0, "Logic Order");
IsBuy=true;
}
if(TradeIsOk && SymbolOpenOrders(Symbol())>=1)
{
//arr=Cascade_trading(_Symbol,lotSize,IsBuy,ask,bid,TakeProfit,StopLoss,StopLossPoints,MinimumStopLossPoints,R2R,true, SymbolOpenOrders(Symbol()));
//TakeProfit=arr.NewTakeProfit;
//StopLoss=arr.NewStopLoss;
}
}

