Posts: 3
Please rate this topic Current rating: 0 Votes: 0
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 
Log in or register to get download access!

Log in » Register »

cruelzhang
Banned
Offline
  • From: United Kingdom
  • Registered: 08-25-18
  • Posts: 22
  • Gender: male
  • Age: 31
  • 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 
Log in or register to get download access!

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 »

How to Install a Forex EA?


How to Install a Forex EA?



NOTE: Only open-source Forex robots allowed to upload. 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.

All User-Generated Content shall be for information purposes only. While MT4talk shall endeavor to provide you with accurate information on its Website, MT4talk shall not be responsible for the accuracy or reliability of User Generated Content. As such you agree to access the Website and use the Services at your own risk. You shall be solely and exclusively responsible for all User Generated Content you upload or post on the Website. You hereby grant MT4talk (i) an irreversible, non-exclusive, royalty-free and fully-paid, worldwide license to reproduce, distribute, publicly display and perform, prepare derivative works of, incorporate into other works, and otherwise use and exploit your User Generated Content, and (ii) the right to include the User Generated Content on the Website.  You hereby irreversibly waive any claims and assertions of moral rights or attribution with respect to your User-Generated Content.

Only open source forex trading software used to automate online trading decisions/signals (“Forex Trading Robots”) shall be uploaded by you onto the Website. MT4talk prohibits the uploading of copyrighted, hacked or illegal versions of forex trading robots on to the Website. MT4talk may remove any copyrighted hacked or illegal versions of forex trading robots from its Website and may close your Member Account (defined below) should you upload copyrighted, hacked or illegal versions of forex trading robots on to the Website. Forex Trading Robots that have been uploaded on the Website, may undergo a simulated back-test on an actual forex account by our tester team, solely for the purposes of providing you with a starting point for your own back-test and for educational purposes only. 

To use the MT4talk forum, you must agree on the Terms of use and Privacy & Cookies Policy!


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 or the MT4talk EA Tester Team 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.


Affiliates Disclaimer - The site may contain links to affiliate websites, and we receive an affiliate commission for any sign up that trade by you on the affiliate website using such links. Our affiliate partner includes the following: FXopen, FBS, LQDFX, MyForexVPS, KickEX.

Copyright MT4talk.com Forum Rules - Privacy Policy.