How to fix Close[1] & Close[2]

How to fix Close[1] & Close[2]

Manage alerts

Loading saved threads...

comandante993fp · External communityPost link
External question — Stack Overflow Stack Exchange Author: comandante993fp Original post: https://stackoverflow.com/questions/69426837 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have a problem with my EA trades, now I will show you the code with a screenshot of a trade (it happens often) I see that I was definitely wrong for how the entry below must read I put an image where it explains what I have in mind void OnTimer() { //--- if (currBars != Bars){ calculate_price_levels(); //debug_levels(); check_nearest_levels(); if (is_session()){ if (Close[2] < Nearest_Up_Level && Close[1] >= Nearest_Up_Level && isAvailableOrder()){ //Print("BUY entry, Nearest_Up_Level:",Nearest_Up_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]); double lot = _get_lot_size (Stop_Loss); OpenTrade(Symbol(), OP_BUY, lot); } if (Close[2] > Nearest_Down_Level && Close[1] <= Nearest_Down_Level && isAvailableOrder()){ //Print("SELL entry, Nearest_Down_Level:",Nearest_Down_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]); double lot = _get_lot_size (Stop_Loss); OpenTrade(Symbol(), OP_SELL, lot); } } currBars = Bars; } if (Trailing_Stop > 0) trail_sl(); // if (BE > 0) check_be(); int trades_number = _get_number_of_trades(); if (trades_number < Trades_Number_0) check_last_trade_result(); Trades_Number_0 = trades_number; } void check_nearest_levels(){ int size = ArraySize(Price_Levels); for (int i = 0; i < size; i++){ if (Close[2] > Price_Levels[i] && Close[2] < Price_Levels[i + 1]){ Nearest_Down_Level = Price_Levels[i]; Nearest_Up_Level = Price_Levels[i + 1]; BUY_TP_Price = 0; if (size > i + 2) BUY_TP_Price = Price_Levels[i + 2]; else BUY_TP_Price = Nearest_Up_Level + StepPips * Point * mp; Next_BUY_TP_Price = 0; if (size > i + 3) Next_BUY_TP_Price = Price_Levels[i + 3]; else Next_BUY_TP_Price = BUY_TP_Price + StepPips * Point * mp; SELL_TP_Price = 0; if (i >= 1) SELL_TP_Price = Price_Levels[i - 1]; else SELL_TP_Price = Nearest_Down_Level - StepPips * Point * mp; Next_SELL_TP_Price = 0; if (i >= 2) Next_SELL_TP_Price = Price_Levels[i - 2]; else Next_SELL_TP_Price = SELL_TP_Price - StepPips * Point * mp; break; } } } Example of what I want to do
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: comandante993fp Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/questions/69426837 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have a problem with my EA trades, now I will show you the code with a screenshot of a trade (it happens often) I see that I was definitely wrong for how the entry below must read I put an image where it explains what I have in mind void OnTimer() { //--- if (currBars != Bars){ calculate_price_levels(); //debug_levels(); check_nearest_levels(); if (is_session()){ if (Close[2] < Nearest_Up_Level && Close[1] >= Nearest_Up_Level && isAvailableOrder()){ //Print("BUY entry, Nearest_Up_Level:",Nearest_Up_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]); double lot = _get_lot_size (Stop_Loss); OpenTrade(Symbol(), OP_BUY, lot); } if (Close[2] > Nearest_Down_Level && Close[1] <= Nearest_Down_Level && isAvailableOrder()){ //Print("SELL entry, Nearest_Down_Level:",Nearest_Down_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]); double lot = _get_lot_size (Stop_Loss); OpenTrade(Symbol(), OP_SELL, lot); } } currBars = Bars; } if (Trailing_Stop > 0) trail_sl(); // if (BE > 0) check_be(); int trades_number = _get_number_of_trades(); if (trades_number < Trades_Number_0) check_last_trade_result(); Trades_Number_0 = trades_number; } void check_nearest_levels(){ int size = ArraySize(Price_Levels); for (int i = 0; i < size; i++){ if (Close[2] > Price_Levels[i] && Close[2] < Price_Levels[i + 1]){ Nearest_Down_Level = Price_Levels[i]; Nearest_Up_Level = Price_Levels[i + 1]; BUY_TP_Price = 0; if (size > i + 2) BUY_TP_Price = Price_Levels[i + 2]; else BUY_TP_Price = Nearest_Up_Level + StepPips * Point * mp; Next_BUY_TP_Price = 0; if (size > i + 3) Next_BUY_TP_Price = Price_Levels[i + 3]; else Next_BUY_TP_Price = BUY_TP_Price + StepPips * Point * mp; SELL_TP_Price = 0; if (i >= 1) SELL_TP_Price = Price_Levels[i - 1]; else SELL_TP_Price = Nearest_Down_Level - StepPips * Point * mp; Next_SELL_TP_Price = 0; if (i >= 2) Next_SELL_TP_Price = Price_Levels[i - 2]; else Next_SELL_TP_Price = SELL_TP_Price - StepPips * Point * mp; break; } } } Example of what I want to do

Cancel quote

Checking account access…