Hola a todos,
Ya casi he terminado mi método de creación del EA de Little Big Man, pero estoy atascado en un punto de lógica.
He adjuntado mi código a continuación porque puedes ver, y esto es todo sobre la función Martingale ().
Todo el propósito de este EA es obtener ganancias modestas, cuando las pequeñas ganancias se queden estancadas (rezagados), luego saldré de estas a 200 (o 'X') pips del precio de entrada.
Tengo mi configuración lógica por defecto, ya que cada 200 pips, el comercio se cerrará, luego se abrirá un nuevo comercio en su ubicación 1,5 veces multiplicado.
Por lo tanto, he calculado una ganancia de BE para ese comercio perdido. Pero:
1) El cálculo no está funcionando correctamente, ya que estoy recuperando solo 15.50 después de la reducción de 20.00 en el primer nivel;
2. No puedo recuperar si los niveles han pasado. L2 se ingresa a 200 pips y podría ser .02 lotes, L3 se ingresa a 400 pips y podría ser .03 lotes, L4 se ingresa a 600 pips y puede ser .05 lotes, etc. No se acercará ni siquiera a la recuperación.
¿Alguien por favor me puede ayudar con cómo realizar esto? Gracias.
Aquí está la versión corta de lo que he hecho hasta ahora:
NewMultiplierTakeProfit = ((OrderOpenPrice () * OrderLots ()) (Ask * NewLotSize))((OrderLots () NewLotSize));/Calcule el nuevo beneficio
Código insertado/ --------------------------------------------- --------------------- /| REAV_EA. Mq4 |/| Copyright © 2010, Kenny Hubbard |/| http://www.compu-forex.com |/ ----------------------------------------------- ------------------- #property copyright © 2010, Kenny Hubbard # enlace de propiedad http://www.compu-forex.com #define NO_RESULT -10 extern int MagicNumber = 100; extern doble Eq_StopLoss = 10000; Doble riesgo externo = 0.01; externo doble Trail_From = 8; externo doble Trail_Max = 50.0; extern doble Trail_Percent = 20; extern double Grid_Size = 13; extern int MinimumReEntry = 200; Multiplicador externo doble = 1.5; extern int MinimumProfit = 1; int D_Factor = 1, LotDigits = 1, Slippage = 3, Retries = 10; Double Anchor, Pip, Grid_Min = 0, Grid_Max = 0, Grid_Ord_OpenPrice # 91; # 93; # 91; two # 93 ;, Auto_Grid, NewMultiplierTakeProfit = 0, NewLotSize = 0; string Order_Cmt = Little Big Man EA;/ ----------------------------------------------- ------------------- /| servicio de inicialización pro |/ ----------------------------------------------- ------------------- int init () Pip = Etapa;/- si (Dígitos == 3/ ------------------------------------- ----------------------------- /| pro función de desinicialización |/ ---------- -------------------------------------------------- ------ int deinit ()/-/- return (0);/ ----------------------- ------------------------------------------- /| función de inicio experta |/ ---------------------------------------------- -------------------- int start () int result = NO_RESULT;/- if (! OrdersTotal ()) Print (Haciendo un primer comercio); OrderSend (Symbol (), 4, Get_Lots (Risk), NormalizeDouble (Ask Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Blue); OrderSend (Symbol (), 5, Get_Lots (Risk), NormalizeDouble (Bid-Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Blue); Update_Grid (Grid_Min, Grid_Max); resultado Check_For_Trade (Grid_Min, Grid_Max); if (result! = NO_RESU LT) Do_Trade (resultado); Trail_Stop (); Martingale (); dual BuyLevel = (Bid - (MinimumReEntry * Pip)); dual SellLevel = (Ask (MinimumReEntry * Pip)); Comentario (Nivel de compra :, (Nivel de compra), \ n, Nivel de cotización:, (Nivel de venta), \ n, Oferta:, Oferta, \ n, Pregunta:, Preguntar, \ n, Reingreso mínimo :, MinimumReEntry, \ n/Point :, NormalizeDouble (MinimumReEntry * Point, 10), \ n,/Pip :, NormalizeDouble (MinimumReEntry * Pip, 10));/- return (0);/ ----------------------------------------------- ------------------- void Martingale ()/Función para eliminar las órdenes actuales de rezagados para (int xo = 0; xo lt; OrdersTotal (); xo ) if (OrderSelect (xo, SELECT_BY_POS)) RefreshRates (); if (OrderType () == 0) if (OrderOpenPrice () gt; = (Bid (MinimumReEntry * Pip))) NewLotSize = Multiplicador * OrderLots (); NewMultiplierTakeProfit = ((OrderOpenPrice () * OrderLots ()) (Ask * NewLotSize))((OrderLots () NewLotSize));/Calcule el nuevo beneficio si (OrderClose (OrderTicket (), OrderLots (), Ask, 99, rojo)) OrderSend (Symbol (), 0, NormalizeDouble (NewLotSize, LotDigits), Ask, Slippage, 0, NormalizeDouble ((NewMultiplierTakeProfit (MinimumProfit * Pip)), 10), Multiplied Order, MagicNumber, 0, Blue); if (OrderType () == 1) if (OrderOpenPrice () lt; = (Ask - (MinimumReEntry * Pip))) NewLotSize = Multiplicador * OrderLots (); NewMultiplierTakeProfit = ((OrderOpenPrice () * OrderLots ()) (Bid * NewLotSize))(OrderLots () NewLotSize);/Calcule new take profit if (OrderClose (OrderTicket (), OrderLots (), Ask, 99, Rojo)) OrderSend (Symbol (), 1, NormalizeDouble (NewLotSize, LotDigits), Bid, Slippage, 0, NormalizeDouble ((NewMultiplierTakeProfit- (MinimumProfit * Pip)), 10), Multiplied Order, MagicNumber, 0, Blue);/ ----------------------------------------------- ------------------- void Update_Grid (double Min, double Max) int Order_Cnt = 0, Grid_Num = 0; para (int I = 0; ilt; OrdersTotal (); I ) if (OrderSelect (I, SELECT_BY_POS)) if (OrderType () gt; 3) Order_Cnt ; else Print (Error al seleccionar Orden = GetLastError ()); ArrayResize (Grid_Ord_OpenPrice, Order_Cnt); ArrayInitialize (Grid_Ord_OpenPrice, 0.0); para (I = 0; ilt; OrdersTotal (); I ) if (OrderSelect (I, SELECT_BY_POS)) if (OrderType () gt; 3) Grid_Ord_OpenPrice # 91; Grid_Num # 93; # 91; 0 # 93; = OrderOpenPrice (); Grid_Num ; else Print (Error al seleccionar Orden = GetLastError ()); ArraySort (Grid_Ord_OpenPrice); Min = Grid_Ord_OpenPrice # 91; 0 # 93; # 91; 0 # 93 ;; Max = Grid_Ord_OpenPrice # 91; Order_Cnt-1 # 93; # 91; 0 # 93 ;;/ ----------------------------------------------- ------------------- int Check_For_Trade (doble Min, double Max) si (Ask gt; = Max Auto_Grid) devuelve (OP_BUYSTOP); if (Bid lt; = Min - Auto_Grid) return (OP_SELLSTOP); return (NO_RESULT);/ ----------------------------------------------- ------------------- void Do_Trade (int Buy_or_Sell) caso de cambio (Buy_or_Sell) OP_BUYSTOP: int ticket = OrderSend (Symbol (), OP_BUYSTOP, NormalizeDouble (Get_Lots (Risk) , LotDigits), NormalizeDouble (Ask Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Green);Delete_Opposite_Trade (5); ticket = OrderSend (Symbol (), OP_SELLSTOP, NormalizeDouble (Get_Lots (Risk), LotDigits), NormalizeDouble (Bid - 2 * Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Red); descanso; caso OP_SELLSTOP: ticket = OrderSend (Symbol (), OP_SELLSTOP, NormalizeDouble (Get_Lots (Risk), LotDigits), NormalizeDouble (Bid - Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Red); Delete_Opposite_Trade (4); ticket = OrderSend (Symbol (), OP_BUYSTOP, NormalizeDouble (Get_Lots (Risk), LotDigits), NormalizeDouble (Ask 2 * Auto_Grid, Digits), Slippage, 0,0, Order_Cmt, MagicNumber, 0, Green); descanso; por defecto: Alert (Se desconoce el tipo de orden); descanso; regreso;/ ----------------------------------------------- ------------------- void Delete_Opposite_Trade (int Del_B_S) para (int I = 0; ilt; OrdersTotal (); I ) OrderSelect (I, SELECT_BY_POS); if (OrderMagicNumber () == MagicNumber) if (OrderType () == Del_B_S) OrderDelete (OrderTicket ());/ ----------------------------------------------- ------------------- doble Get_Lots (doble lRisk) doble Lots = AccountEquity () * lRisk100/1000; if (MarketInfo (Symbol (), MODE_MINLOT) gt; Lotes) Lotes = MarketInfo (Symbol (), MODE_MINLOT); if (MarketInfo (Symbol (), MODE_MAXLOT) lt; Lotes) Lotes = MarketInfo (Symbol (), MODE_MAXLOT); retorno (Lotes);/ ----------------------------------------------- ------------------- bool Trail_Stop () {bool mod, lresult = false; doble My_Profit, My_Trail, My_SL, lTrail_Max, lTrail_From, Stop_Level;/- para (int I = 0; I lt; OrdersTotal (); I ) {if (OrderSelect (I, SELECT_BY_POS, MODE_TRADES)) {if (OrderMagicNumber () == MagicNumber) {RefreshRates ();/****************************** HARDCODED PARA AHORA HASTA MEJOR SOLUCIÓN, A.01 LOTES, POR LA CUENTA DE 10K ¡FUNCIONA! ************************* if (OrderLots () lt; 0.02) lTrail_Max = Trail_Max * Pip; lTrail_From = Trail_From * Pip; Stop_Level = MarketInfo (OrderSymbol (), MODE_STOPLEVEL) * Pip; Caso de cambio (OrderType ()) OP_BUY: My_Profit = Bid - OrderOpenPrice (); My_Trail = MathMin (My_Profit * Trail_Percent100, lTrail_Max); My_SL = NormalizeDouble (OrderClosePrice () - My_Trail, Digits); lresult = true; if (My_Profit gt; lTrail_From) if (OrderClosePrice () - My_SL gt; Stop_Level) if (OrderStopLoss () lt; My_SL Split; case OP_SELL: My_Pp.P.P.P. ); My_SL = NormalizeDouble (Ask My_Trail, Digits); lresult = true; if (My_Profit gt; lTrail_From) if (My_SL - OrderClosePrice () gt; Stop_Level) break (! (! Mod GetLastError () gt; 1) Print ( Error al ingresar al final del rastreo - Error GetLastError ());}} else Imprimir (Error sel orden de detección); }/- return (lresult); }