Change settings of strategy with autotrading  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Change settings of strategy with autotrading

Postby evdl » 23 Apr 2015

Looking for an solution for the following scenario:

Have a strategy that automatically enters and exits trades.

Sometimes you want to manually interfere your autotrading because of situations you notice while watching the screens. For example block long or short trades or block trading during news events.

Want to have a textbox on the chart and use it as a button (for example call it "block long trades") and when you click on this textbox the long trades are blocked until you manually unblock it. But the autotrader continues trading. Without stopping it and restarting it.

Is this possible and anyone have ideas to achieve this (with mouseclick events or another way?).

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Change settings of strategy with autotrading

Postby hughesfleming » 24 Apr 2015

This is a good question. I have been playing around with the idea of coding a control panel in Purebasic with a few buttons and making dll. I have been able to code a few simple things and compile a dll without problems. Many thanks to Fu510n on BMT for explaining how to do this. I am not sure if this would work but it might be worth a try.

There is a threading problem with Purebasic so it might not be the best choice for everything but probably the simplest if you work around its limitations.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Change settings of strategy with autotrading

Postby TJ » 24 Apr 2015

Looking for an solution for the following scenario:
Have a strategy that automatically enters and exits trades.
Sometimes you want to manually interfere your autotrading because of situations you notice while watching the screens. For example block long or short trades or block trading during news events.
Want to have a textbox on the chart and use it as a button (for example call it "block long trades") and when you click on this textbox the long trades are blocked until you manually unblock it. But the autotrader continues trading. Without stopping it and restarting it.

Is this possible and anyone have ideas to achieve this (with mouseclick events or another way?).
You already have the solution.

THere are some code examples of mouseclick events in this forum... you can easily use them to adapt to your needs.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Change settings of strategy with autotrading  [SOLVED]

Postby evdl » 25 Apr 2015

Did some searching on the forum and found a topic of John Bowles with a script that I adjusted a bit. Thank you John for the template.

Code below shows a button to block/unblock long trades when using autotrade with the use of MC_Text_GetActive. With GV a value is send to the script of the signal. This value is used in the signal to block or unblock the code to enter long trades.

This is the indicator on the chart:

Code: Select all

{With thanks to John Bowles for the template of this indicator

see: http://www.multicharts.com/discussion/viewtopic.php?f=5&t=7764}


Inputs:
LongTradeButton_from_Top(0.06), // The distance the text Start command will be from the top of the chart

Vars: // long trade button
Intrabarpersist LongTrade(0),
Text_ID_LongTrade_ON(0),
Text_ID_LongTrade_OFF(0),
Intrabarpersist Text_Location_LongTrade(0),
Intrabarpersist ProcessDone_LongTrade_ON("N"),
Intrabarpersist ProcessDone_LongTrade_OFF("N"),
Intrabarpersist LongTradeButton_horizontal(0), // horizontally setting
Intrabarpersist AdjustableLongTradeButton_Location(0), // vertical setting
Intrabarpersist LongTradeButton_offscreen_Location(0), // off screen setting
Intrabarpersist ButtonLongTrade_ON_location(0), // combination of horizontal and vertical setting
Intrabarpersist ButtonLongTrade_OFF_location(0); // combination of horizontal and vertical setting

Vars: // overall location variabels
Intrabarpersist ScreenValHighest(0),
Intrabarpersist ScreenValLowest(0),
Intrabarpersist ScreenBeginTime(0),
Intrabarpersist ScreenEndTime(0),
OneMinuteDT(ELTimeToDateTime(1)); // 1 minute time unit


// OVERALL VARIABELS ===================================

// location on screen
ScreenValHighest = GetAppInfo(aiHighestDispValue); // Highest price on the screen
ScreenValLowest = GetAppInfo(aiLowestDispValue); // Lowest price on the screen
ScreenBeginTime = GetAppInfo(aiLeftDispDateTime); // first date and time on screen
ScreenEndTime = GetAppInfo(aiRightDispDateTime); // last date and time on screen

// =================================================


// LONG TRADE BUTTON ===================================
if CurrentBar = 1 then begin
{Create the buttons on the first bar so you do not have to wait to start executing it}
Text_ID_LongTrade_ON = Text_New(Date,Time,0," LONG TRADES ON");
Text_ID_LongTrade_OFF = Text_New(Date,Time,0," LONG TRADES OFF");
end; // end of if CurrentBar = 1 then begin


If LastBarOnChart then Begin

// long trades on button active
If MC_Text_GetActive = Text_ID_LongTrade_ON
then begin

If ProcessDone_LongTrade_ON = "N"
and LongTrade = 0
then begin

LongTrade = 1; // set: take long trades to OFF

ProcessDone_LongTrade_ON = "Y"; // set "ON" proces to done, otherwise it will keep running.
ProcessDone_LongTrade_OFF = "N"; // set "OFF" proces to the start position
Playsound("C:\WINDOWS\Media\Notify.wav"); // The notify sound tells you the process is done
end;

end; // end of If MC_Text_GetActive = Text_ID_LongTrade_ON


// long trades off button active
If MC_Text_GetActive = Text_ID_LongTrade_OFF
then begin

If ProcessDone_LongTrade_OFF = "N"
and LongTrade = 1
then begin

LongTrade = 0; // set: take long trades to ON

ProcessDone_LongTrade_OFF = "Y"; // set "OFF" proces to done, otherwise it will keep running.
ProcessDone_LongTrade_ON = "N"; // set "ON" proces to the start position
Playsound("C:\WINDOWS\Media\Notify.wav"); // The notify sound tells you the process is done
end;

end; // end of If MC_Text_GetActive = Text_ID_LongTrade_OFF


// set location and format text

LongTradeButton_horizontal = datetime2eltime(ScreenEndTime - (OneminuteDT * 0.001) ); // Space horizontally
AdjustableLongTradeButton_Location = ScreenValHighest - ((ScreenValHighest - ScreenValLowest) * LongTradeButton_from_Top);
LongTradeButton_offscreen_Location = ScreenValHighest + 1000;

If LongTrade = 0 then begin
ButtonLongTrade_ON_location = Text_SetLocation(Text_ID_LongTrade_ON, Date, LongTradeButton_horizontal, AdjustableLongTradeButton_Location);
value1 = Text_SetBorder(Text_ID_LongTrade_ON, True);
value2 = Text_SetBGColor(Text_ID_LongTrade_ON, DarkGreen);
value3 = Text_SetColor(Text_ID_LongTrade_ON, White);
value4 = Text_SetSize(Text_ID_LongTrade_ON, 13);
value5 = Text_SetAttribute(Text_ID_LongTrade_ON, 1, true);
value6 = Text_SetStyle(Text_ID_LongTrade_ON,1, 1);
value7 = Text_SetLocation(Text_ID_LongTrade_OFF,Date, Time, LongTradeButton_offscreen_Location); // set button off screen
end;

If LongTrade = 1 then begin
ButtonLongTrade_OFF_location = Text_SetLocation(Text_ID_LongTrade_OFF, Date, LongTradeButton_horizontal, AdjustableLongTradeButton_Location);
value8 = Text_SetBorder(Text_ID_LongTrade_OFF, True);
value9 = Text_SetBGColor(Text_ID_LongTrade_OFF, DarkRed);
value10 = Text_SetColor(Text_ID_LongTrade_OFF, White);
value11 = Text_SetSize(Text_ID_LongTrade_OFF, 13);
value12 = Text_SetAttribute(Text_ID_LongTrade_OFF, 1, true);
value13 = Text_SetStyle(Text_ID_LongTrade_OFF,1, 1);
value14 = Text_SetLocation(Text_ID_LongTrade_ON, Date, Time, LongTradeButton_offscreen_Location);
end;


end; // end of If LastBarOnChart then Begin
// ================================ END LONG TRADE BUTTON


// send long trades on/off status to signal
GVSetNamedFloat("long trade button", LongTrade); // value 1 = off, value 0 is on

// use this for updating the textbox every second
Recalclastbarafter(1);
Use this in your signal to retrieve the GV value that is send from the indicator:

Code: Select all

Vars:
LongTrade(0),
Errorcode(9999);


LongTrade = GVGetNamedFloat("long trade button", errorcode); // value 1 = off, value 0 is on


If LongTrade = 0 then begin

"your buy long trade code"

end;


Return to “MultiCharts”