GET-SET Signals for GV

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

GET-SET Signals for GV

Postby maxmax68 » 21 Apr 2017

Code: Select all

//
// By Massimo Rizzi (Italy)
//
// Signal to set a Global Variable with the marketposition(0)*currentcontracts of the chart
// and to send it to the Get-Signal
//
// You can choose the GV-Index number
// SHIFT+CLICK on text boxes to Active-Pause or to Reset to zero GV if paused
//

[ProcessMouseEvents = True];
[IntrabarOrderGeneration=True];
RecalcLastBarAfter(1);

inputs:
GV_Index(0),
Text_Size(8);

vars:
recalcpersist PosizioneChart(0),
recalcpersist textid1(0),
recalcpersist textid1_counter(0),
recalcpersist textid2(0),
recalcpersist textid2_counter(0);



if currentbar=1 then begin
DefineDLLFunc: "GlobalVariable.dll", int, "GV_SetInteger", int, int ;
DefineDLLFunc: "GlobalVariable.dll", int, "GV_GetInteger", int ;
textid1=text_new_dt (datetime, close,"");
text_setbgcolor(textid1,black);
Text_SetBorder(textid1,true);
Text_SetSize(textid1,Text_Size);
textid2=text_new_dt (datetime, close,"");
text_setbgcolor(textid2,black);
Text_SetBorder(textid2,true);
Text_SetSize(textid2,Text_Size);
text_setcolor(textid2,magenta);


end;

if LastBarOnChart_s then begin
//
// If MouseClickShiftPressed ...
//
if MouseClickShiftPressed then begin
//
// Checks for MouseClick on TextBox1 and updates textid1_counter
//
if MC_Text_GetActive=textid1 then begin
textid1_counter=textid1_counter+1;
if textid1_counter>1 then textid1_counter=0;
end;
//
// Checks for MouseClick on TextBox2: if TextBox1 paused then resets GV
//
if MC_Text_GetActive=textid2 then begin
textid1_counter=0;
value1=GV_SetInteger(GV_Index,0);
end;
end;
//
// Se bottone attivato (textid1_counter=1) ...
//
if textid1_counter=1 then begin
text_setcolor(textid1,cyan);
PosizioneChart=marketposition(0)*currentcontracts;
value1=GV_SetInteger(GV_Index,PosizioneChart);
value2=GV_GetInteger(GV_Index);
end
//
// se invece bottone in pausa (textid1_counter=0) ...
//
else if textid1_counter=0 then begin
text_setcolor(textid1,lightgray);
//value1=GV_SetInteger(GV_Index,0);
value2=GV_GetInteger(GV_Index);
end;
//
// Aggiorna Text Boxs
text_setlocation_dt(
textid1,
datetime,
getappinfo(aiLowestDispValue)+0.1*(getappinfo(aiHighestDispValue)-getappinfo(aiLowestDispValue))
);
Text_SetString(textid1,"GV("+NumToStr(GV_Index,0)+"):"+NumToStr(value2,0)+" MP:"+numtostr(marketposition(0)*currentcontracts,0));
text_setlocation_dt(
textid2,
getappinfo(aiLeftDispDateTime)+0.5*(getappinfo(aiRightDispDateTime)-getappinfo(aiLeftDispDateTime)),
getappinfo(aiLowestDispValue)+0.1*(getappinfo(aiHighestDispValue)-getappinfo(aiLowestDispValue))
);
Text_SetString(textid2,"Azzera GV("+NumToStr(GV_Index,0)+")");
end;
//print (textid1_counter:0:0);

Code: Select all

//
// By Massimo Rizzi (Italy)
//
// Signal to Get the sum of currentcontracts*marketposition from other charts via Global Variables
// and to send market orders to the actual chart
//
// You can choose the interval GV-Index number from wich receive data
// SHIFT+CLICK on text boxes to Active-Pause
//

[ProcessMouseEvents = True];
[IntrabarOrderGeneration=true];
RecalcLastBarAfter(1);

Inputs:
GV_Start_Index(1),
GV_End_Index(1),
Max_Contracts_Qty(3),
EOD_Time_s(173800),
TimeOut_Bars(2),
Text_Size(8);

Variables:
recalcpersist Counter(0),
recalcpersist Posizione_Globale_Attuale(0),
recalcpersist Posizione_Globale_Precedente(0),
recalcpersist Chart_MP(0),
recalcpersist Broker_MP(0),
recalcpersist textid(0),
recalcpersist textid_counter(0),
recalcpersist text_string(""),
recalcpersist bInit(true),
recalcpersist Bar_Counter(0);

//
if currentbar=1 then begin
DefineDLLFunc: "GlobalVariable.dll", int, "GV_SetInteger", int, int ;
DefineDLLFunc: "GlobalVariable.dll", int, "GV_GetInteger", int ;
text_string="GV Int:"+NumToStr(GV_Start_Index,0)+"-"+NumToStr(GV_End_Index,0);
textid=Text_new_DT(datetime, c,text_string);
Text_SetBorder(textid,true);
text_setbgcolor(textid,black);
Text_SetSize(textid,Text_Size);
bInit=true;
Bar_Counter=0;
textid_counter=0;
end;
// if not auto set to paused
if getappinfo(aistrategyauto)=0 then textid_counter=0;

if LastBarOnChart_s and getappinfo(airealtimecalc)=1 and getappinfo(aistrategyauto)=1 then begin

Chart_MP=currentcontracts*marketposition;
Broker_MP=MarketPosition_at_Broker;

//
// If MouseClickShiftPressed ...
//
if MouseClickShiftPressed then begin
//
// Checks for MouseClick on TextBox and updates textid_counter
//
if MC_Text_GetActive=textid then begin
textid_counter=textid_counter+1;
if textid_counter>1 then textid_counter=0;
end;
end;


//
// Se orario prima dell'ora EOD e active
if time_s<EOD_Time_s and textid_counter=1 then begin
// All'inizio
// controlla e allinea posizione del broker con posizione della chart
If bInit=true then begin
if Broker_MP>Chart_MP then begin
//Buy su chart
ChangeMarketPosition((Broker_MP-Chart_MP),close,"I_Buy");
Chart_MP=currentcontracts*marketposition;
Broker_MP=MarketPosition_at_Broker;
end;
if Broker_MP<Chart_MP then begin
//Sell su chart
ChangeMarketPosition((Broker_MP-Chart_MP),close,"I_Sell");
Chart_MP=currentcontracts*marketposition;
Broker_MP=MarketPosition_at_Broker;
end;
//
Posizione_Globale_Attuale=MarketPosition_at_Broker;
Posizione_Globale_Precedente=MarketPosition_at_Broker;
bInit=false;
end;

//
// Se non allineamento chart-broker aspetta x barre poi allinea chart-broker
If Chart_MP<>Broker_MP then begin
Text_SetColor(textid,red);
if barstatus(1)=2 then Bar_Counter=Bar_Counter+1;
if Bar_Counter=TimeOut_Bars then begin
if Broker_MP>Chart_MP then begin
//Buy su chart
ChangeMarketPosition((Broker_MP-Chart_MP),close,"S_Buy");
Chart_MP=currentcontracts*marketposition;
Broker_MP=MarketPosition_at_Broker;
end;
if Broker_MP<Chart_MP then begin
//Sell su chart
ChangeMarketPosition((Broker_MP-Chart_MP),close,"S_Sell");
Chart_MP=currentcontracts*marketposition;
Broker_MP=MarketPosition_at_Broker;
end;
//
Posizione_Globale_Attuale=MarketPosition_at_Broker;
Posizione_Globale_Precedente=MarketPosition_at_Broker;
Bar_Counter=0;
end;
end
// invece
// se allineamento chart-broker ok, allora allinea Posizione Globale Attuale-Precedente global variables
else begin
Bar_Counter=0;
Text_SetColor(textid,cyan);
//
// Calcola Posizione Globale Attuale
Counter=0;
Posizione_Globale_Precedente=Posizione_Globale_Attuale;
Posizione_Globale_Attuale=0;
for Counter= GV_Start_Index to GV_End_Index begin
Value1=GV_GetInteger(counter);
Posizione_Globale_Attuale=Posizione_Globale_Attuale+value1;
End;
//
// Controlla e ridimensiona Posizione Globale Attuale con Max Quantita Tradabile
If Posizione_Globale_Attuale>Max_Contracts_Qty then Posizione_Globale_Attuale=Max_Contracts_Qty;
If Posizione_Globale_Attuale<-1*Max_Contracts_Qty then Posizione_Globale_Attuale=-1*Max_Contracts_Qty;
//
// Confronta Posizione Globale Attuale con Posizione Globale Precedente e corregge con ordine Market e cambio posizione chart
if Posizione_Globale_Attuale>Posizione_Globale_Precedente then begin
//Buy
if PlaceMarketOrder(true, true, (Posizione_Globale_Attuale-Posizione_Globale_Precedente))=true
then ChangeMarketPosition((Posizione_Globale_Attuale-Posizione_Globale_Precedente),close,"Buy");
end;
if Posizione_Globale_Attuale<Posizione_Globale_Precedente then begin
//Sell
if PlaceMarketOrder(false, true, (Posizione_Globale_Precedente-Posizione_Globale_Attuale))=true
then ChangeMarketPosition((Posizione_Globale_Attuale-Posizione_Globale_Precedente),close,"Sell");
end;
end;
end
//
// se orario >= orario EOD e active mette tutto flat
else if textid_counter=1 then begin
if barstatus(1)=2 then begin
Broker_MP=MarketPosition_at_Broker;
if Broker_MP<0 then begin
//Buy
if PlaceMarketOrder(true, true, (-1*Broker_MP))=true
then ChangeMarketPosition((-1*Broker_MP),close,"EOD_Buy");
end;
if Broker_MP>0 then begin
//Sell
if PlaceMarketOrder(false, true, (Broker_MP))=true
then ChangeMarketPosition((-1*Broker_MP),close,"EOD_Sell");
end;
Posizione_Globale_Precedente=0;
Posizione_Globale_Attuale=0;
end;
end;
end;

//
// Aggiorna Text Box
If textid_counter=1 then text_setcolor(textid, cyan) else text_setcolor(textid, lightgray);
text_setlocation_dt(
textid,
datetime-0.0070,
getappinfo(aiLowestDispValue)+0.1*(getappinfo(aiHighestDispValue)-getappinfo(aiLowestDispValue))
);
text_string="GV("+NumToStr(GV_Start_Index,0)+"-"+NumToStr(GV_End_Index,0)+"):"
+NumToStr(Posizione_Globale_Attuale,0)
+" MP:"+NumToStr(marketposition*currentcontracts,0)+" MPB:"+NumToStr(marketposition_at_broker,0);
Text_SetString(textid,text_string);



Return to “User Contributed Studies and Indicator Library”