답변완료
수식 문의드립니다.
안녕하세요.
일전에 만들어주신 수식인데요..
차트에 장착해보니 Plot3만 보이고 나머지 1,2,4가 보이질 않습니다.
Ai에게 물어보니
1. plot1, plot2, plot4 함수 호출 시기
plot1, plot2, plot4 함수는 매 바(bar)마다 호출되어야 하지만, 현재 코드에서는 longtsl, shorttsl, mid 값이 변경될 때만 호출되고 있습니다. 따라서 이들 값이 변경되지 않으면 차트에 표시되지 않습니다.
2. active 변수 사용
plot1, plot2, plot4 함수에서 active 변수를 사용하여 조건부 색상을 지정하고 있습니다. 하지만 active 변수는 longtsl이 변경될 때만 업데이트되므로, shorttsl이 변경되어도 차트 색상이 변경되지 않습니다.
해결 방법
1.plot1, plot2, plot4 함수를 매 바마다 호출하도록 수정합니다.
2.active 변수 대신 pos 변수를 사용하여 조건부 색상을 지정합니다.
이렇게 답변을 하길래 혼자 이래저래 해봤는데 잘 않됩니다.
죄송하지만 선 좀 보일수 있게 다시 한번 검토 부탁드립니다.
아래는 작성해주신 수식입니다.
input : stp("Auto");
input : prd(20);
input : perc(0.5);
input : bias("Auto");
input : upcol(Green);
input : dncol(Red);
input : upcol1(lime);
input : dncol1(maroon);
var : b(0),hi(0),lo(0),ph(0),pl(0),phl(0),pll(0),dir(0);
var : cnt(0);
Array : peaks[1000](0);
b = index;
hi = highest(high,prd*10);
lo = lowest(low,prd*10);
ph = iff(NthHighestBar(1,high, prd) == 0 , high , ph);
pl = iff(NthLowestBar(1,low, prd) == 0 , low , pl);
phL = iff(NthHighestBar(1,high, prd) == 0 , b , phL);
plL = iff(NthLowestBar(1,low, prd) == 0 , b , plL);
dir = iff(phL>plL , 1 , -1);
if dir!=dir[1] Then
{
In*sertArray(peaks, 0, iff(dir>0 , (ph[1]-pl)/ph[1] , (ph-pl[1])/pl[1])) ; //*삭제 (장착시에는 * 삭제했습니다)
cnt = cnt+1;
}
var : autocalc(0),SwitchTrue(0),SwitchFalse(0);
autocalc = iff(cnt == 0 ,0 , MedianArray(peaks, cnt));
if stp == "Auto" Then
{
SwitchTrue = low-(low*autocalc);
Switchfalse = high+(high*autocalc);
}
if stp == "Percentage" Then
{
SwitchTrue = low-(low*(perc/100));
Switchfalse = high+(high*(perc)/100);
}
if stp == "Pivot" Then
{
SwitchTrue = pl;
Switchfalse = ph;
}
var : longtsl(0),shorttsl(0),pos(0);
if low<=longtsl Then
{
longtsl = Switchtrue;
shorttsl = Switchfalse;
pos = -1;
}
if high>=shorttsl then
{
longtsl = Switchtrue;
shorttsl = Switchfalse;
pos = 1;
}
pos = iff(bias=="Bullish",1, IFf(bias=="Bearish",-1,pos));
var : active(False),mid(0);
active = longtsl==longtsl[1];
plot1(longtsl,"ltl",iff(active,IFF(pos>0,dncol,upcol),Black));
plot2(shorttsl,"stl",iff(active,iff(pos>0,upcol,dncol),Black));
plot3(close,"c");
mid = Avg(longtsl,shorttsl);
plot4(mid,"Mid",iff(active,rgb(125, 196, 255),black));
2024-05-19
839
글번호 179687
지표
답변완료
진입가격별 청산수식
진입가격에 따른 청산수식 작성해보았습니다.
바른지요?
#포지션 있을 때
if MarketPosition != 0 Then
{
if Entryprice >= dayopen and Entryprice < dayopen+1.25 Then
{
SetStopLoss(1,PointStop);
SetStopTrailing(2,0,PointStop,1);
}
Else if Entryprice >= dayopen+1.25 and Entryprice < dayopen+2.5 Then
{
SetStopLoss(1.5,PointStop);
SetStopTrailing(2.5,0,PointStop,1);
}
Else
{
SetStopLoss(2,PointStop);
SetStopTrailing(3,0,PointStop,1);
}
}
Else #무포지션이면 해제
{
SetStopLoss(0);
SetStopTrailing(0,0);
}
2024-08-01
657
글번호 179680
시스템