How do you usually exeute trades calculated by Position Size Calculator?

  • Manually

    Votes: 12 15.2%
  • PSC-Trader script with a mouse click

    Votes: 13 16.5%
  • PSC-Trader with a keyboard shortcut

    Votes: 51 64.6%
  • Using third-party trading panel

    Votes: 2 2.5%
  • Other (please provide details)

    Votes: 1 1.3%

  • Total voters
    79
  • Poll closed .
Status
Not open for further replies.

heggna

Active Trader
Sep 4, 2018
10
4
34
44
Hey Enivid

Massive thanks for your great Position Size Calculator! It's an outstanding tool. I've studied it very keenly while also reading articles on MQL5.com and familiarizing myself with the MQL GUI-Library so that I can learn how to make my own GUI. Right now, I am adapting your GUI to my own personal needs, moving buttons and labels around, resizing and arranging everything, adding preset-SL-buttons, buy and sell buttons etc.

While going through your code, I may have stumbled upon an error. I'm refering to the MT4 version "PositionSizeCalculator.mq4".

In OnInit, I believe you've written the following code to prevent the attachment of a duplicate indicator, so that there won't be two instances of PositionSizeCalculator on the same chart:

MQL4:
// Prevent attachment of second panel if it is not a timeframe/parameters change.
if (GlobalVariableGet("PSC-" + IntegerToString(ChartID()) + "-Flag") > 0) GlobalVariableDel("PSC-" + IntegerToString(ChartID()) + "-Flag");
else
{
    int indicators_total = ChartIndicatorsTotal(0, 0);
    for (int i = 0; i < indicators_total; i++)
    {
        if (ChartIndicatorName(0, 0, i) == "Position Size Calculator")
        {
            Print("Position Size Calculator is already attached.");
            return(INIT_FAILED);
        }
    }
}


This works to prevent two separate panels from being created during timeframe changes, but the code under the "else" statement doesn't work to prevent a second indicator named PositionSizeCalculator from being attached to the chart. When the user attempts to add a second instance of PSC to the chart:
  • The code if (ChartIndicatorName(0, 0, i) == "Position Size Calculator") will return false because you've changed the short-name of the first indicator to "Position Size Calculator"+ChartID().
  • The above method of checking whether the same indicator is already running is incorrect: When you add an indicator to the chart, it is included in the list of indicators, even if initialization has not been completed. The above code would fail even if there were no indicators on the chart and you tried to add the first instance of PSC, because ChartIndicatorName(0, 0, i) will return PSC name, since PSC has already been added to the list of indicators. If you add a second indicator, ChartIndicatorsTotal will count a total of 2 indicators even before OnInit is done executing, and so on.
My own code to prevent the attachment of a second instance of the same indicator is as follows:

MQL4:
//Check if there are 2 instances of the indicator. If there are, the 2nd instance of the indicator fails its initialization and exits from the chart.
int totalIndicatorsOnChart = ChartIndicatorsTotal(0,0);
int instances = 0;
for (int i = 0; i < totalIndicatorsOnChart; i++)
{
   //Iterate through all indicators, and if you happen upon an instance of the indicator, increment "instances" by 1.
   if (ChartIndicatorName(0,0,i) == "Indicator_Name")   instances++;      
}
if (instances >= 2)  return(INIT_FAILED);


Let me know if my analysis is correct. I've tried it on my terminal and was able to attach two PSC indicators on the same chart, which obviously produces errors.

In any case, keep up the outstanding work!! I've learned a lot from studying your code.

heggna
 
Last edited:
  • 👍
Reactions: Enivid

heggna

Active Trader
Sep 4, 2018
10
4
34
44
A slight correction to my earlier post where I said: "The above code would fail even if there were no indicators on the chart and you tried to add the first instance of PSC, because ChartIndicatorName(0, 0, i) will return PSC name, since PSC has already been added to the list of indicators."

On reflection, a first indicator can be added to the chart, but again, because the code is erroneous.

The sequence of events is as follows:

First indicator added >> its shortname is initially "PositionSizeCalculator" >> When this shortname is compared to "Position Size Calculator", it returns false >> shortname changed to "Position Size Calculator"+ChartID() >> indicator is placed on chart

Second indicator added >> 2nd indicator's shortname is initially "PositionSizeCalculator" >> When this shortname is compared to "Position Size Calculator", it returns false >> shortname changed to "Position Size Calculator"+ChartID() >> 2nd instance of indicator added to chart
 
  • 👍
Reactions: Enivid

heggna

Active Trader
Sep 4, 2018
10
4
34
44
Another point I just realized: When the duplicate indicator which is accidentally placed on the chart fails its initialization, it will run its de-initialization code. But we don't want the duplicate indicator to execute any code in OnDeInit which would destroy chart objects, Terminal GV's and the like which are currently being used by the first indicator. So we would have to put something like
MQL4:
if (duplicateIndicator()) return;
at the very beginning of the OnDeInit function so that the duplicate indicator exits immediately without doing any damage. duplicateIndicator() would be the function which checks for a duplicate indicator.

Also, duplicateIndicator() must be executed FIRST in OnInit so that no chart objects or Terminal GV's are created before it is established whether we have a duplicate indicator on the chart.
 
Last edited:
  • 👍
Reactions: Enivid

heggna

Active Trader
Sep 4, 2018
10
4
34
44
Hey Enivid

I'm busy building my own GUI and making it more robust against bugs and the like, so I'd really appreciate your input on something, if would would kindly oblige...

In the PSC for MT4:
What is the purpose of HideShowMaximize? What is the bug/problem you are trying to work around? If the program didn't have HideShowMaximize, what problem would occur and under what conditions? In your commentary in QCPositionSizeCalculator::OnClickBtnAccount, you've written that HideShowMaximize
MQL4:
// Hides and shows the panel. Needed to put it to the foreground. Maximize() hides internal controls that were hidden before.
I can't quite make sense of this. When does the panel ever go into the background? And what are the internal controls you're referring to?

Your help appreciated

heggna
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,252
1,508
144
Odesa
www.earnforex.com
As far as I remember (and I might be mistaken), it solves two issues:
1. A simple one - it moves the whole panel to the chart's foreground.
2. A tricky one - it resets the panel's window internal controls to a proper state. Panel's window internal controls are the close ('x') button and the minimize/maximize button.
 

denislh

Trader
Sep 22, 2018
1
0
6
83
Hi everyone,
I downloaded the PostionSizeCalculator.mq5 and I see it listed inside the Data Folder, but it is not showing up in the Navigator under my Indicators.

Can any offer any suggestion on how to rectify this, please?

Regards,
Denis
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,252
1,508
144
Odesa
www.earnforex.com
Hello Denis,

The PostionSizeCalculator.mq5 is not enough. You need to download the whole folder, which consists of three files:
  • Defines.mqh
  • PositionSizeCalculator.mq5
  • PositionSizeCalculator.mqh
The folder with these three files should be copied to /MQL5/Indicators/ folder of your MetaTrader 5 data folder.

You also need to restart MT5 or compile PostionSizeCalculator.mq5 manually.
 

Alexter

Active Trader
Jul 3, 2018
28
16
39
Hi everyone. Thanks again Enivid for the the great support and the great calculator.
i wanted to add an update of the calculator I shared here some time ago.
This update is the same as last time but I migrated it to google docs so that it can be more flexible for people and for it to not rely on MT4 to get the price data.
This means that any trader can now use this calculator.

Hope this is useful to some people here.
https://docs.google.com/document/d/1-oUtyB0jCz_6Q5SO9ZfH1TcH_DaK4oES7JfV0MQG0Yc/edit?usp=sharing
 
  • 👍
Reactions: Enivid

Poker_player

Active Trader
Jul 26, 2017
23
3
29
25
Hello,

Is there some guide somewhere how could I use it in my expert advisor? Or I have to myself dig into the code and find how to use?

I am noob at mql language :)
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,252
1,508
144
Odesa
www.earnforex.com
There is no guide, but it is pretty straightforward - you just read the chart objects values (e.g., XXXXXm_EdtPosSize for position size, where XXXXX is the random number given to the PSC panel when it initializes) and use them in your EA. You can also see the source code of the PSC-Trader script to see how it reads the values.
 

Poker_player

Active Trader
Jul 26, 2017
23
3
29
25
There is no guide, but it is pretty straightforward - you just read the chart objects values (e.g., XXXXXm_EdtPosSize for position size, where XXXXX is the random number given to the PSC panel when it initializes) and use them in your EA. You can also see the source code of the PSC-Trader script to see how it reads the values.

aha. And I need to somehow write to the chart objects. I thought maybe this is not necessary, maybe I could call some functions directly instead of writing and reading from chart. Because bot does not need to see the user inputs anyway.
I imagine could be function like calculateLotSize(SLprice, enterPositionPrice, riskAmount, ...) parameters - various fields and it returns the lot size. Maybe that would be easier? (an idea to do this)
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,252
1,508
144
Odesa
www.earnforex.com
You mean you want to make your EA calculate the same stuff the indicator calculates? That definitely will be much more difficult and would require you to adapt lots of its functionality to the EA.
 

kizac72

Active Trader
May 7, 2014
9
0
37
Hi,

Need help. I copied and pasted the 3 files into MT4 indicators folder. However, nothing happens when i try to use or attach to chart.
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,252
1,508
144
Odesa
www.earnforex.com
Hi,

Need help. I copied and pasted the 3 files into MT4 indicators folder. However, nothing happens when i try to use or attach to chart.

Did you try compiling the PositionSizeCalculator.mq4 file?

When you attach PositionSizeCalculator to the chart, what does it output in the Experts tab of your MT4 Terminal?
 

kizac72

Active Trader
May 7, 2014
9
0
37
Did you try compiling the PositionSizeCalculator.mq4 file?

When you attach PositionSizeCalculator to the chart, what does it output in the Experts tab of your MT4 Terminal?


Capture.PNG

It is blank when i click on the PSC indicator. Nothing happens.

Not quite sure about compiling. But I followed the instructions, open the PSC mqh file in metaeditor. Clicked compile.

Capture.PNG Capture1.PNG
 
Status
Not open for further replies.