Advertisement


Posts: 3
Please rate this topic Current rating: 3.0 Votes: 1
RSS
andy.penez
FREE Member
Offline
  • From: Germany
  • Registered: 04-25-19
  • Posts: 2
  • Gender: male
  • Age: 108
  • Email

Count Bars from indicator

Hi, have the following problem, I would like to use a trend indicator in my strategy (see Att_1).
In my test EA (see Att_2) is an example for OpenBuyOrder with MACD and for CloseLongPositions with ForexTrend_v2, currently only with value = 1.

How can I now determine that CloseLongPositions is only executed if the trend bars are at red for five periods or bars (see bottom snapshot), if they are less than five then nothing should be done!

Have tried everything possible with operands FOR, PeriodSeconds () .. unfortunately without success.

Thank you in advance for your help!

https://mt4talk.com/img/m/36310/5cc1f9d58353c9.18263262.jpg

ATT_1 - ForexTrend_v2.mq4 2.91 kb, 4 downloads since 2019-04-25 
ATT_2 - Test_EA.mq4 7.88 kb, 3 downloads since 2019-04-25 
You are not logged in!

Log in Register

cruelzhang
Banned
Offline
  • From: United Kingdom
  • Registered: 08-25-18
  • Posts: 22
  • Gender: male
  • Age: 30
  • Email
  • Thanks: 4

try it

 //Close Long Positions
   double c0 = iCustom(NULL, PERIOD_CURRENT, "ForexTrend_v2", 7, 50.6, 3000, 0, 0);
   double c1 = iCustom(NULL, PERIOD_CURRENT, "ForexTrend_v2", 7, 50.6, 3000, 0, 1);
   double c2 = iCustom(NULL, PERIOD_CURRENT, "ForexTrend_v2", 7, 50.6, 3000, 0, 2);
   double c3 = iCustom(NULL, PERIOD_CURRENT, "ForexTrend_v2", 7, 50.6, 3000, 0, 3);
   double c4 = iCustom(NULL, PERIOD_CURRENT, "ForexTrend_v2", 7, 50.6, 3000, 0, 4);
   if( c0 == 1 && c1 == 1 && c2 == 1 && c3 == 1 && c04 == 1 //ForexTrend_v2 is equal to fixed value
   )
     {   
      if(IsTradeAllowed())
         myOrderClose(OP_BUY, 100, "");
      else //not autotrading => only send alert
         myAlert("order", "");
     }

ATT_2 - Test_EA.mq4 8.28 kb, 4 downloads since 2019-04-26 
You are not logged in!

Log in Register

andy.penez
FREE Member
Offline
  • From: Germany
  • Registered: 04-25-19
  • Posts: 2
  • Gender: male
  • Age: 108
  • Email

Hithanks for your help and fast response, but unfortunately the code doesn’t work correctly, the CloseLongPositions reacts strange.
Itcloses on red AND on blue bars, and as it looks it also doesn’t count correctly (see snapshot).
 https://mt4talk.com/img/m/36310/5cc36346cefa52.74561920.jpg
 
Dou youhave any other Ideas, how I can solve this indicator issue?
 
P.S. Asit looks the I’ve made a mistake, value 1 should be for the red colour and 0 for the blue (see code below). But it doesn’t solve the upper described problem.
https://mt4talk.com/img/m/36310/5cc363579df5a5.70971052.png

Login or Register for FREE!

You are not logged in to the MT4talk forum!

Log in Register

Online Users & Stats
  • Total number of registered users: 45,115
  • Newest registered user: Mohammedzaman
  • Total number of topics: 11,634
  • Total number of posts: 38,072

Online users: 1,592 guests, 145 Members:

Ac Williams, Achmad, Adamm, adexlaw, admin, agenorpaz, Agung Setiawan, AKALLAI86, akinssun, AltTuv77, Andile, Anointed Alphonse, armingrivas, Ashfaque, attila.koritar, badass_trader, bbrashea, BmForex, Bratanon, bustapa, candyboy_tushar, card2006, carl132, Carlixton, Cepi Suryadi Marwan, Chanon Zack, cicche98, Clint, coachklso, Damaris Perez, damos002, Daniel Stadelmann, Deepak, Denis Maxime, Diogo Sawitzki Cansi, Dipali@6161, Donnie Drajat, Eds01, Eduardo Zurk, Egor1811, elishaab, enaso, Etsenn, fauzi19, ferrysmit, firoozi1392, flsekme, Forex Ipfx, Forexangel, Frank Kipke, fredd, gilfx, hamakachal, hemantpremi, hiramindiaz, hofmatte, ian.kungu, ian69, johnfufa, joyrat, juragantrading, Kamani Gautam, Kcty, KenFongers, kozura, kris69one, Kubilay Örnek, kv1984, Kyosuke Tagawa, lucio, magdie123, MarianNick123, markiboy, Masaki Robust, MINNE, Mohammedzaman, Mohan Chinnarasu, Morgan Cypher, muczika, Mwila Bwalya, nadamnla, nileshpatel, noeltg, Nuel0, ogicjp, omtei, Orvin Castanha, oski, papyrus, Paulinho Zaccariotto, peter2017, picazzo_ozzacip, Pillarforex, Prateek Samuel, Profit Forex, pulimal9, quintana, Rana Anas, Rassie, Raymond#7372, rugira82, Sankiraibi, sasastephe, sathavnp, Shahir Zjk, sharimulyono, shaun, Soe Lin Tun, Stanley Moss, Stefano Meleri, stigmaniac.fx, sya88rol, Taposki99, Tassie007, Tengku Azman, thanet, thirxx84, ThreeLions, TradeHound32, tradingralf, tuhanku1, Ukluck, vduubus, viperscalper, vrmech, vufx1972, Wael El Madhoun, walidshahbudin, whallacesilva, wodan, wtrbuff, xalvinlimx, YaasirCadde, yaojintong, Ylts, yuan, Yuser Al Bardan, Yusri Waiyuesarai, Zachie, Zack Pht, zedeai, Zoltan0013, zorbafx69, zzzpoin, 鈴木優斗

NOTE: Hacked or illegal versions of copyrighted Forex robots are highly prohibited on MT4talk.com. If you upload any illegal version of any copyrighted Forex robot, your forum account will be banned. No exceptions.

MT4talk is a User Generated Content website. All content uploaded to MT4talk by our users (MT4talk forum members) is User Generated Content. 


To use the MT4talk forum, you must agree to these terms! - MT4talk.com is a self-service Forex forum! You can only download open source Forex robots that other forum members are uploading! All Forex robots that tested by the MT4talk EA tester team, is it's a back-test on a real Forex account. The MT4talk EA tester team making the back-test on this website is to give you a starting point, however, you should always make your own test. All tests provided on this forum are provided for education purposes! MT4talk does not provide guarantee or support for the Forex robots listed on the forum!


CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS, IN GENERAL, ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

Disclaimer - No representation is being made that any Forex account will or is likely to achieve profits or losses similar to those shown on backtests in this forum. In fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. Hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk in actual trading. All information on this forum is for educational purposes only and is not intended to provide financial advice. Any statements posted by forum members about profits or income expressed or implied, do not represent a guarantee. Your actual trading may result in losses as no trading system is guaranteed. You accept full responsibilities for your actions, trades, profit or loss, and agree to hold the MT4talk team and forum members of this information harmless in any and all ways.

Copyright MT4talk.com Forum Rules - Privacy Policy.