jurgen
17th January 2011, 04:25 AM
I copied the profit stop for tradesim VitC code and tried to change for a profit stop during the day ie High > profit stop rather than close:
This is the mess I made:
void ProfitStopHigh(float _PercentThreshold)
{
bool InTrade=false; // boolean variable used for trade flag
float EntryPrice=0; // variable used to store the entry price on trade entry
float ProfitThreshold=0; // variable used to hold the profit threshold price
for(int i=0;i<BarCount;i++) // loop for all bars
{
Result[i]=0; // initialize result for each bar
if(!InTrade && User1[i]>0) // check if not in a trade and valid entry trigger
{
InTrade=true; // set the flag
EntryPrice=Open[i]; // set the entry price (WHY???)
// calculate the profit threshold price
ProfitThreshold=User2[i]*(1 + _PercentThreshold/100);
Result[i]=1; // mark a valid entry condition (WHY??? alredy triggered in meta)
}
if(InTrade) // if in the trade do the check
{
if(High[i] >= ProfitThreshold) // check for a profit stop condition
{
Result[i]+=2;
ExitPrice = ProfitThreshold; // threshold reached so mark a valid exit condition
InTrade=false; // reset the flag
}
}
}
}
An error comes up exitprice is already allocated (which is true is MS script) - but why is EntryPrice reset earlier? (when it is set in Meta)
How can the exitprice (based on threshold of profit stop during day) be returned from the script to metastock?
and
Why is EntryPrice set to open[i] array anyway - when it is already done in Meta code?
and
Why does the entrytrigger have to be returned to meta - when it is already used as an argument (user1) for the script. I would have thought that the Result[i] could simply be used for the exittrigger (for tradesim run).
Whilst Im new to VitC Ive done a fair bit of C# and old fortran programming but still dont get whats going on here (from this script)
cheers
This is the mess I made:
void ProfitStopHigh(float _PercentThreshold)
{
bool InTrade=false; // boolean variable used for trade flag
float EntryPrice=0; // variable used to store the entry price on trade entry
float ProfitThreshold=0; // variable used to hold the profit threshold price
for(int i=0;i<BarCount;i++) // loop for all bars
{
Result[i]=0; // initialize result for each bar
if(!InTrade && User1[i]>0) // check if not in a trade and valid entry trigger
{
InTrade=true; // set the flag
EntryPrice=Open[i]; // set the entry price (WHY???)
// calculate the profit threshold price
ProfitThreshold=User2[i]*(1 + _PercentThreshold/100);
Result[i]=1; // mark a valid entry condition (WHY??? alredy triggered in meta)
}
if(InTrade) // if in the trade do the check
{
if(High[i] >= ProfitThreshold) // check for a profit stop condition
{
Result[i]+=2;
ExitPrice = ProfitThreshold; // threshold reached so mark a valid exit condition
InTrade=false; // reset the flag
}
}
}
}
An error comes up exitprice is already allocated (which is true is MS script) - but why is EntryPrice reset earlier? (when it is set in Meta)
How can the exitprice (based on threshold of profit stop during day) be returned from the script to metastock?
and
Why is EntryPrice set to open[i] array anyway - when it is already done in Meta code?
and
Why does the entrytrigger have to be returned to meta - when it is already used as an argument (user1) for the script. I would have thought that the Result[i] could simply be used for the exittrigger (for tradesim run).
Whilst Im new to VitC Ive done a fair bit of C# and old fortran programming but still dont get whats going on here (from this script)
cheers